Skip to content
Advertisement

Compare two arrays and print out Index of row in python

I have two arrays A and B

JavaScript

I want to compare a couple of the elements of A[:,2:4] with couple elements of B[:,2:4] and print out the rows where they are equal or approximate? Here is my approach just for only A[:,3]

JavaScript

How can I do it with both A[:,2] and A[:,3] ?

Many thanks

Advertisement

Answer

I think you are looking for something like this:

JavaScript

You compare B with each row of A, taking into consideration only few indexes.

Thus you:

  • Check if B is close to a row of A (in selected indexes) with np.isclose(_)
  • Keep only rows where all selected indexes are close, with np.all(_, axis=1)
  • Get index of such rows with np.where

If you want to make sure to only output one row of B per cycle, just use np.where(_)[0][0]

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement