2

I have two numpy arrays or two pandas dataframes with three columns and different number of rows.

I want to find where the rows of the first array exist in the second array. Something like matlab's ismember function

[~, idx] = ismember(a, b, 'rows')

Is there a similar function in python? I do not want to use a loop.

gnikol
  • 227
  • 2
  • 9
  • Inner merge with dataframes [merge](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html) – ALollz Mar 19 '18 at 19:56
  • Thank you for your answer but I do not want to merge the two dataframes. I want to find the indices where the two dataframes have equal rows. – gnikol Mar 19 '18 at 20:08
  • you could still use merge and set the argument `indicator=True` and then sort by the `_merge` column. – ALollz Mar 19 '18 at 20:28

1 Answers1

0
import numpy_indexed as npi
idx = npi.indices(a, b)
Eelco Hoogendoorn
  • 10,459
  • 1
  • 44
  • 42