Hello, how can you derive or just find out the coordinate itself (not the value in a given coordinate) of the matrix element, in order to work directly with it (the coordinate of the element). for example, the coordinate m1 = [1,2] is worth 1, but we don’t actually know what coordinate it is in, I want to find out, show it on the screen.

rol = 5
col = 6
m1 = np.zeros (((rol, col))
m1 [1,2] = 1

  • Add to the question the code in which you work with the matrix. - ThePyzhov
  • it is not clear what exactly you do not understand. “Find coordinates” - go through a double cycle on the elements, comparing their values ​​with the desired one. print coordinates” - for example, with the print operator. - aleksandr barakin

1 answer 1

Something like this:

 import numpy as np rol = 5 col = 6 m1 = np.zeros((rol, col)) m1[1, 2] = 1 value_to_find = 1 for i in range(rol): for j in range(col): if m1[i][j] == value_to_find: print('Нашли значение `{}` в позиции ({}, {})'.format(value_to_find, i, j))