<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 28, 2014 at 8:40 AM, Julian Taylor <span dir="ltr"><<a href="mailto:jtaylor.debian@googlemail.com" target="_blank">jtaylor.debian@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 28.11.2014 09:37, Robert Kern wrote:<br>
> On Fri, Nov 28, 2014 at 8:22 AM, Julian Taylor<br>
</span>> <<a href="mailto:jtaylor.debian@googlemail.com">jtaylor.debian@googlemail.com</a> <mailto:<a href="mailto:jtaylor.debian@googlemail.com">jtaylor.debian@googlemail.com</a>>><br>
<div><div class="h5">> wrote:<br>
>><br>
>> On 28.11.2014 04:15, Alexander Belopolsky wrote:<br>
>> > I probably miss something very basic, but how given two arrays a and b,<br>
>> > can I find positions in a where elements of b are located?  If a were<br>
>> > sorted, I could use searchsorted, but I don't want to get valid<br>
>> > positions for elements that are not in a.  In my case, a has unique<br>
>> > elements, but in the general case I would accept the first match.  In<br>
>> > other words, I am looking for an array analog of list.index() method.<br>
>><br>
>> np.where(np.in1d(a, b))<br>
><br>
> Only if the matching elements in `b` have the same order as they do in `a`.<br>
><br>
<br>
</div></div>seems to work also if unordered:<br>
In [32]: a = np.arange(1000)<br>
<br>
In [33]: b = np.arange(500,550, 3)<br>
<br>
In [34]: np.random.shuffle(a)<br>
<br>
In [35]: np.random.shuffle(b)<br>
<br>
In [36]: np.where(np.in1d(a, b))<br>
Out[36]:<br>
(array([  0, 106, 133, 149, 238, 398, 418, 498, 533, 541, 545, 589, 634,<br>
        798, 846, 891, 965]),)</blockquote></div><div><br></div><div>I meant that the OP is asking for something stricter than that. He wants this array of indices to be in the order in which those matching elements appear in `b` so that he can use this information to merge two datasets.</div><div><br></div>-- <br><div class="gmail_signature">Robert Kern</div>
</div></div>