我目前正在使用Anaconda的Spyder,并且我正在尝试将包含类型Float的数组转换为int类型:
x = np.array([1, 2, 2.5])
x.astype(int)
print x
结果仍然没有改变:
[1. 2. 2.5]
为什么会这样?
发布于 2018-07-25 18:48:42
astype 返回一个新数组: https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.astype.html
你需要将结果分配给x
:
In [298]: x = x.astype(int)
In [299]: x
Out[299]: array([1, 2, 2])
https://stackoverflow.com/questions/-100005755
复制相似问题