0
0

More than 3 years have passed since last update.

python3におけるforループの計算速度

Posted at

python3におけるforループの計算速度

競技プログラミングをした際に学んだpythonにおけるfor文の計算速度がコード依存性についてのまとめ。

pythonには、配列の記述方法として通常のlistとnumpyのndarrayがある。
行列計算をする場合、numpyを用いるほうが何かと便利なので全てnumpyのndarrayを利用していた。
しかしfor文を書く際、むやみにnp.arange()を用いるとかなり計算速度が遅くなる。

ex_bad.py
for i in np.arange( 5 ):
    print( i )
ex_good.py
for i in range( 5 ):
    print( i )
0
0
0

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
0
0