On 25 Nov 2012, at 00:29, numpy-discussion-request(a)scipy.org wrote:
>
> Message: 3
> Date: Sat, 24 Nov 2012 23:23:36 +0100
> From: Da?id <davidmenhur(a)gmail.com>
> Subject: Re: [Numpy-discussion] numpy where function on different
> sized arrays
> To: Discussion of Numerical Python <numpy-discussion(a)scipy.org>
> Message-ID:
> <CAJhcF=2nmVeeQUo5Q45OUcQK+7KnQ_u0tvzUyOSXGpQbLSUy+Q(a)mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> A pure Python approach could be:
>
> for i, x in enumerate(a):
> for j, y in enumerate(x):
> if y in b:
> idx.append((i,j))
>
> Of course, it is slow if the arrays are large, but it is very
> readable, and probably very fast if cythonised.
Thanks for all the answers. In that particular case speed is not important (A is 360x720 and b and c is lower than 10 in terms of dimension). However, I stumbled across similar comparison problems in IDL a couple of times where speed was crucial.
My own solution or attempt was this:
==
def fu(A, b, c):
for x, y in zip(b,c):
indx = np.where(A == x)
A[indx] = y
return A
==
>
>
>
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.