Python'astype'不起作用 [英] Python 'astype' not working
本文介绍了Python'astype'不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用Anaconda的Spyder,并且尝试将包含float类型的数组转换为int类型:
I am currently using Spyder from Anaconda and I am trying to convert an array containing type float to type int:
x = np.array([1, 2, 2.5])
x.astype(int)
print x
结果仍然不变:
[1. 2. 2.5]
有想法吗?
推荐答案
astype
返回一个新数组.您需要将结果分配给x
:
In [298]: x = x.astype(int)
In [299]: x
Out[299]: array([1, 2, 2])
这篇关于Python'astype'不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文