[SciPy-User] Finding Positions of Identical Entries in Arrays of Different Size
Lorenzo Isella
lorenzo.isella at gmail.com
Thu Aug 27 18:31:06 EDT 2009
Dear All,
A problem which should be rather easy, but which is giving me a hard time.
(1) Consider for instance the following two arrays
A=[12,78,98,654,7665,1213,765] and
B=[98,765, 654]
Now, what I need is an efficient way of finding the positions of the
entries of A equal to the entries of B, that is to say in the case of
the two arrays above (counting from zero)
C=[2,6,3].
Note that in the example there is a single entry of A equal to the i-th
entry of B.
I have tried using scipy.where, but unsuccessfully. Any ideas about how
to code that efficiently?
(2) I would like to extend this to the case where A and B are m times n
arrays, e.g. consider the case
A= 233 789
987 734
890 253
876 321
534 489
and
B= 987 734
876 321
and C is now the 1D vector returning the positions of the rows of A
equal to those of B, i.e.
C=[1, 3].
Any suggestions is really welcome.
Kind Regards
Lorenzo
More information about the SciPy-User
mailing list