热线电话:13121318867

登录
2019-02-22 阅读量: 819
数据格式错误

问题描述:ufunc 'isnan' not supported for the input types, and the inputs could not be safely

将一个list矩阵转化为numpy数组之后,使用np.isnan()方法,报出了这么一个错误:

TypeError: ufunc ‘isnan’ not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’

经过测试,发现是二维list转化为numpy数组的时候就存在问题了。

出错原因是list第二维的元素个数不一致导致如:

list1 = [[1, 2, 3],

[4, 5, 6],

[7, 8, 9, 10]]

这时候使用 np.array(list1),输出如下内容:

[

list(1, 2, 3),

list(4, 5, 6),

list(7, 8, 9, 10)

]

接着使用np.isnan()方法,就会报出最上面的错误。

因为第三行是4个元素,所以无法转化为我们想要的numpy数组,解决方法就是将列数改为一致即可。

0.0000
0
关注作者
收藏
评论(0)

发表评论

暂无数据