Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
numpy の arange 関数を使用して、次の範囲を作成しました。
a = n.arange(0,5,1/2)
この変数はそれ自体で正常に機能しますが、スクリプトのどこかに配置しようとすると、次のエラーが表示されます
ZeroDivisionError: ゼロ除算
新しいバージョンの python (3.1 以降だと思います) を使用していない場合、整数除算を想定しているため、式 1/2 はゼロに評価されます。
これを修正するには、1/2 を 1./2 または 0.5 に置き換えるかfrom __future__ import division、スクリプトの先頭に置きます。
from __future__ import division