M = A[..., np.newaxis] == B<div><div><br></div><div>will give you a 40x60x20 boolean 3d-array where M[..., i] gives you a boolean mask for all the occurrences of B[i] in A.</div><div><br></div><div>If you wanted all the (i, j) pairs for each value in B, you could do something like</div>
<div><br></div></div><div>import numpy as np</div><div>from itertools import izip, groupby</div><div>from operator import itemgetter</div><div><br></div><div>id1, id2, id3 = np.where(A[..., np.newaxis] == B)</div><div>order = np.argsort(id3)</div>
<div>triples_iter = izip(id3[order], id1[order], id2[order])</div><div>grouped = groupby(triples_iter, itemgetter(0))</div><div>d = dict((b_value, [idx[1:] for idx in indices]) for b_value, indices in grouped)<br></div><div>
<br></div><div>Then d[value] is a list of all the (i, j) pairs where A[i, j] == value, and the keys of d are every value in B.</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 24, 2012 at 3:36 PM, Siegfried Gonzi <span dir="ltr"><<a href="mailto:sgonzi@staffmail.ed.ac.uk" target="_blank">sgonzi@staffmail.ed.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all<br>
<br>
This must have been answered in the past but my google search capabilities are not the best.<br>
<br>
Given an array A say of dimension 40x60 and given another array/vector B of dimension 20 (the values in B occur only once).<br>
<br>
What I would like to do is the following which of course does not work (by the way doesn't work in IDL either):<br>
<br>
indx=where(A == B)<br>
<br>
I understand A and B are both of different dimensions. So my question: what would the fastest or proper way to accomplish this (I found a solution but think is rather awkward and not very scipy/numpy-tonic tough).<br>
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888">--<br>
The University of Edinburgh is a charitable body, registered in<br>
Scotland, with registration number SC005336.<br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</font></span></blockquote></div><br></div>