I am working on a puzzle in python.
What I'm trying to do is cover a piece for display.
For example:
gameMap = np.array([[1 0 0] [0 1 0] [0 1 1]]) piece = np.array([[0, 1], [1, 1]])
How can I put a piece on a card to get a result like
[[1 1 0] [1 2 0] [0 1 1]]
Or
[[1 0 0] [0 1 1] [0 2 2]]
Thanks in advance.
One way to “add” your fragment to the map is to use slicing. The key selects a GameMap slice that has the same shape as the slice.
gameMap[0:2, 0:2] += piece
Output:
OR
gameMap[1:3, 1:3] += piece
Another way to do this is to add a second array at the same size as your first array.
print gameMap + np.pad(piece, ((0,1), (0,1)), 'constant') print gameMap + np.pad(piece, ((1,0), (1,0)), 'constant')
, , ( ) , , .
Source: https://habr.com/ru/post/1627537/More articles:Python: printing in two columns - pythonНастройка заголовка настраиваемого запроса при перенаправлении страницы - javascriptScipy: efficiently generate a series of integrations (integral function) - pythonC # regex for a word possibly surrounded by quotation marks - c #Type of casting through composition (interfaces and classes) - javaGeocoderServiceError for geophysics - pythonSetting the Xamarin.Forms Binding in Code - c #How to use jQuery to hide / show specific divs on hover? - javascriptUnable to send Chrome Extension sender callback value - javascriptBest way to handle Reveal JS slide overflow - javascriptAll Articles