counting surrounding true's in numpy matrix (python)
Clash Royale CLAN TAG #URR8PPP counting surrounding true's in numpy matrix (python) I want to make something similiar to minesweeper input matrix: matrix = [[true, false, false], [false, true, false], [false, false, false]] if a bomb is on the field I do not count it as bomb is surrounding. I thought about doing it with numpy convolve somehow but I am struggling with how to go through the matrix and always check the left, top, right and bottom fields of the actual field (in the case of a border I check "empty" fields which is 0 for sure) 2d convolution with a donut-shaped seed. – Daniel F Aug 10 at 8:57 no it doesn't have to be numpy, but I thought that this would be the best solution, just not sure how to get it to work. @DanielF hmm how that? – Dominik Lemberger Aug 10 at 8:58 3 Answers 3 Here is a solution using scipy.signal.convolve2d : scipy.signal.convolve2d import scipy import numpy as np # Input matrix, can be left as boolean mat...