import numpy as np C = np.arange(15).reshape(3, 5) choice = np.where(C!=0) print(choice) #(array([0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2], dtype=int64), array([1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4], dtype=int64)) print(*choice) #[0 0 0 0 1 1 1 1 1 2 2 2 2 2] [1 2 3 4 0 1 2 3 4 0 1 2 3 4] list1=list(map(list, zip(*choice))) print(list1) #[[0, 1], [0, 2], [0, 3], [0, 4], [1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [2, 0], [2, 1], [2, 2], [2, 3], [2, 4]]