如何解决ValueError:无法将大小为0的序列复制到维度为2的数组轴
我从今天开始变得麻木了。 我正在创建一个numpy数组,并用给定的rgb
填充它rgb = (58,129,22)
xy = [0,0]
data = np.zeros( (43,21,2),dtype=np.uint8 )
print(xy)
data[xy[0],xy[1]] = rgb
但是当我运行它时,会出现此错误
[0,0]
Traceback (most recent call last):
File "C:\Users\admin\Desktop\y\Python\0\0.py",line 59,in <module>
data[xy[0],xy[1]] = rgb
ValueError: cannot copy sequence with size 0 to array axis with dimension 2
我该如何解决?
解决方法
什么是rgb
?可以使用空列表(或元组)重现该错误。
In [101]: xy = [0,0]
...: data = np.zeros( (43,21,2),dtype=np.uint8 )
In [102]: data[xy[0],xy[1]]
Out[102]: array([0,0],dtype=uint8)
In [103]: data[xy[0],xy[1]]=1
In [104]: data[xy[0],xy[1]]=[]
Traceback (most recent call last):
File "<ipython-input-104-70fa3a2584fa>",line 1,in <module>
data[xy[0],xy[1]]=[]
ValueError: cannot copy sequence with size 0 to array axis with dimension 2
3元素元组也不起作用:
In [113]: data[xy[0],xy[1]]=(58,129,22)
Traceback (most recent call last):
File "<ipython-input-113-b469af2ddad0>",22)
ValueError: cannot copy sequence with size 3 to array axis with dimension 2
,
好,我发现了问题
rgb
没有得到值