Matrix matrix matplotlib

[ [ 99 66] [118 67] [119 67] [120 67] [121 67] [121 68] [121 70] [ 95 71] [121 71] [123 98] [133 109] [136 110] [150 126] [153 126] [153 128] [153 129]] 

I have this numpy array that contains the coordinate sets that I want to overlay on the matrix. How can I turn this numpy array into something like this

 [[0 1 1 ..., 0 1 1] [0 0 1 ..., 1 1 1] [0 0 0 ..., 1 0 0] ..., [0 0 0 ..., 0 1 0] [1 0 0 ..., 0 0 1] [0 1 0 ..., 1 1 1]]` 

So, I can draw what I want on my matrix

+4
source share
2 answers
 width = max(coord[0] for coord in coordinates) height = max(coord[1] for coord in coordinates) zeros_and_ones = numpy.zeros([width, height]) for x, y in coordinates: zeros_and_ones[x, y] = 1 
0
source

If you have a numpy array, this will most likely be faster (assuming coord positive):

 maxcoord = np.amax(coord, axis=0) zeros_and_ones = numpy.zeros(maxcoord) zeros_and_ones[coord[0], coord[1]] = 1 

If coord consists of integers but has negative values, you can simply rescale it

0
source

Source: https://habr.com/ru/post/1468926/


All Articles