python - Numpy combine two 2d martixs -
i working puzzle in python .
what trying cover piece map .
for example :
gamemap = np.array([[1 0 0] [0 1 0] [0 1 1]]) piece = np.array([[0, 1], [1, 1]]) how can put piece on map can result
[[1 1 0] [1 2 0] [0 1 1]] or
[[1 0 0] [0 1 1] [0 2 2]] thanks in advance .
one way "add" piece map use slicing. key selecting slice of gamemap same shape piece.
gamemap[0:2, 0:2] += piece output:
[[1 1 0] [1 2 0] [0 1 1]] or
gamemap[1:3, 1:3] += piece output:
[[1 0 0] [0 1 1] [0 2 2]]
Comments
Post a Comment