0
a = np.array([[383, 383, 384, 384, 384, 384, 384, 384, 384, 421, 422, 422, 422, 422, 423, 423, 423, 423, 423, 423, 479, 480, 481, 482, 483, 485, 485, 485, 485, 485, 485, 485, 513, 515, 517]])
b = np.array([384, 423, 485])
np.where(a == b[:,None])

returns me two arrays

[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2]
[2, 3, 4, 5, 6, 7, 8, 14, 15, 16, 17, 18, 19, 25, 26, 27, 28, 29, 30, 31]

and i want to join?(i don't know how to call that operation) the two lists by the values of the first one , so the output will be like

[[2, 3, 4, 5, 6, 7, 8], [14, 15, 16, 17, 18, 19], [25, 26, 27, 28, 29, 30, 31]]

how can i do it?

(my final mission is to get the central value of each list in the last array)

baronsec
  • 154
  • 1
  • 10

1 Answers1

0

You can do it like this:

>>> [np.where(a==x)[1] for x in b]
[array([2, 3, 4, 5, 6, 7, 8], dtype=int64),
 array([14, 15, 16, 17, 18, 19], dtype=int64),
 array([25, 26, 27, 28, 29, 30, 31], dtype=int64)]

If you want the output as lists instead of arrays:

>>> [list(np.where(a==x)[1]) for x in b]
[[2, 3, 4, 5, 6, 7, 8], [14, 15, 16, 17, 18, 19], [25, 26, 27, 28, 29, 30, 31]]
not_speshal
  • 22,093
  • 2
  • 15
  • 30