Multiplication by @
, which is available in python3.5 and later.
Benchmark:
use_at
import numpy as np
N=1000
LOOP=10
a=np.arange(N*N).reshape(N,N)
for _ in range(LOOP):
b=a@a@a
use_dot
import numpy as np
N=1000
LOOP=10
a=np.arange(N*N).reshape(N,N)
for _ in range(LOOP):
b=a.dot(a).dot(a)
How to write | time |
---|---|
use_at | user 0m12.344s |
use_dot | user 0m35.812s |
How, @
is about three times faster. I think it depends on the size of the matrix, the type of the value, the processing system, etc., but if you execute the above code at hand, you will get this result.
I was a little surprised.
Recommended Posts