LoginSignup
15
10

More than 5 years have passed since last update.

dot よりも @ が速い

Last updated at Posted at 2017-02-14

python3.5 以降で使えるようになった @ による乗算。

ベンチマークしてみると:

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)
書き方 時間
use_at user 0m12.344s
use_dot user 0m35.812s

なんと、@ の方が三倍ぐらい速い。行列の大きさとか値の型とか処理系とかいろいろによると思うけど、上記のコードを手元て実行したらこんな結果に。

ちょっとびっくりした。

※ python 3.6 で普通に使えるベンチマークライブラリって何?

15
10
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
10