hl = [(1,109),(12,212),(21,23)]
highlightc = np.zeros([N, N])
c = len(highlightc)
colour = [0.21]*c
test = len(number_list) -c
this = [0.21]*test
colour.extend(this)
colour = np.array(colour)
colour = np.array(colour)
print len(number_list)
print colour
for x, y in hl:
highlightc[x, y] = 1##set so binary matrix knows where to plot
h=ax.imshow(highlightc*colour), interpolation='nearest',cmap=plt.cm.spectral_r)
fig.canvas.draw()
我试图创建一个二进制矩阵,其中的图形是不同的颜色。然而,我所绘制的颜色阵列与它们的形状不一样。我得到错误operands could not be broadcast together with shapes (160,160) (241)
我猜(160*160)是矩阵的大小,241是颜色数组的大小。
我有一个坐标数组,我把它变成了一个二进制数组highlightc
。这是成功的阴谋。不过,用颜色我得到了坐标数组的大小,并用它填充一个数组来生成颜色。这显然是错误的。基本上我想要的是一定量的,剩下的是0.21
,其余的是1.0
。那么我怎样才能把我得到的数组变成(160,160)
的形状,这样它就可以用正确的颜色给正确的图形着色呢
就是你所需要的。在
highlgihtc
将在任何地方包含1
,但在一些地方它将是0.21
。在相关问题 更多 >
编程相关推荐