我有两个numpy数组:数据和掩码。面具和数据的大小不同,所以我想象它们像帆布和邮票。如何在不同位置标记我的画布?
import numpy as np
import matplotlib.pyplot as plt
# Make a canvas
canvas = np.zeros( 2500 ).reshape( 50, 50 )
# Make a "stamp"
r = 10
xx, yy = np.mgrid[ :r * 2, :r * 2 ]
stamp = ((xx - r) ** 2 + (yy - r) ** 2) < r**2
# Draw on the canvas
canvas[stamp] = 10
# Display the drawing
plt.imshow(canvas)
plt.show()
我明白了:
我如何在不同的地方盖章以获得这样的东西?
答案 0 :(得分:2)
首先从画布中裁剪出矩形(与图章大小相同)。
# Draw on the canvas
canvas[x_offset : x_offset + stamp.shape[0],
y_offset : y_offset + stamp.shape[1]][stamp] = 10