twitter facebook

TypeError: slice indices must be integers or None or have an __index__ method

以下のようなソースでエラーがでました。
pylab.plot(fs[0:n/2], a[0:n/2])
TypeError: slice indices must be integers or None or have an __index__ method
これで治ります。
pylab.plot(fs[0:n//2], a[0:n//2])
理由は python3では / は実数。 // は整数です。
Python3 の除算
x = 5/2
#結果 2.5

x = 5//2
#結果 2
AUTHOR
@mikomiko
最終更新日 2018/09/17
FAVORITE good stock
LINK TAG
記法を見る
1737000135