0

I've search on author's github and pypi, but could not find any example of using this package. The author mentioned here that this package is fully vectorized. In below example, I would like to find the index of each element of Y in X. Could you please elaborate on how to do so?

import numpy_indexed as npi
X = np.array([0, 4, 3, 5, 1, 2])
Y = np.array([0, 1, 2, 3, 4, 5])

My intended result is [0, 4, 5, 2, 1, 3].

Akira
  • 2,594
  • 3
  • 20
  • 45
  • Not very clear on the intended result or how's numpy_indexed involved. Seems like this could solve it - https://stackoverflow.com/questions/33678543/. Does it? – Divakar Jun 04 '20 at 20:42
  • @Divakar My intended result is `[0, 4, 5, 2, 1, 3]`. When I use the function in your answer `np.nonzero(np.in1d(X, Y))[0]`, I got `array([0, 1, 2, 3, 4, 5], dtype=int64)`, which is not as expected. Could you please suggest a fix? – Akira Jun 04 '20 at 20:49
  • Use `sorter` solution. For specific scenario of positive numbers, there are other answers too. – Divakar Jun 04 '20 at 20:50
  • My array is very large and contains only a permutation of `0, 1, ..., n`. This procedure is repeated several times, please suggest me an approach this is efficient @Divakar. – Akira Jun 04 '20 at 20:52
  • As I said check out other answers too in that thread (Q&A). – Divakar Jun 04 '20 at 20:53
  • Ah I miss understand your comment @Divakar. I though you mean other answers (in other places). Now I got you meant other answers in the same linked question. – Akira Jun 04 '20 at 20:54

0 Answers0