TypeError: only size-1 arrays can be converted to Python scalars

时间:2020-12-14 18:37:06   收藏:0   阅读:2012

问题来源:需要把一个float数组A转为int,于是直接在代码中写了 B=int(A),从而报错。

原因:int函数只能对单个数字进行,而不能对一个数组进行

解决方法:用map函数,对数组中的每个元素整数化

B=list( map( int , A ) )

 

原文:https://www.cnblogs.com/ShineLeBlog/p/14133328.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!