使用numpy.round时出现“ AttributeError:rint”

使用numpy.round时出现“ AttributeError:rint”,第1张

使用numpy.round时出现“ AttributeError:rint”

您不能对作为对象的numpy数组进行四舍五入

astype
,只要可以将数组安全地转换为float即可更改此值:

>>> a = np.random.rand(5).astype(np.object)>>> aarray([0.5137250555772075, 0.4279757819721647, 0.4177118178603122,       0.6270676923544128, 0.43733218329094947], dtype=object)>>> np.around(a,3)Traceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/Library/frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/fromnumeric.py", line 2384, in around    return round(decimals, out)AttributeError: rint>>> np.around(a.astype(np.double),3)array([ 0.514,  0.428,  0.418,  0.627,  0.437])

对于字符串,unipre,void和char类型的数组,您将收到类似的错误。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5666735.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存