首页 > 解决方案 > Numpy 返回“TypeError:'float' 对象不能被解释为整数”

问题描述

这是我的代码:

g = np.reshape(a,(len(a)/width,width)) 
p = g.astype(int) 
print(p)

标签: pythonnumpyreshape

解决方案


len(a)/width will return float

try len(a)//width

even better you can use -1 as first index and np will calculate for you

np.reshape(a,(-1,width))


推荐阅读