报错类型
>>> b
['1', '0.1', '1', '0.1']
>>> b.reshape(2,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'reshape'
解决方案
list不能使用reshape
,需要将其转化为array
,然后就可以使用reshape
了
>>> import numpy as np
>>> np.array(b).reshape(2,2)
array([['1', '0.1'],
['1', '0.1']], dtype='<U3')
搞定,过来点一下赞吧。