[Numpy-discussion] numpy where function on different sized arrays
Siegfried Gonzi
sgonzi@staffmail.ed.ac...
Sun Nov 25 03:22:58 CST 2012
On 25 Nov 2012, at 00:29, numpy-discussion-request@scipy.org wrote:
>
> Message: 3
> Date: Sat, 24 Nov 2012 23:23:36 +0100
> From: Da?id <davidmenhur@gmail.com>
> Subject: Re: [Numpy-discussion] numpy where function on different
> sized arrays
> To: Discussion of Numerical Python <numpy-discussion@scipy.org>
> Message-ID:
> <CAJhcF=2nmVeeQUo5Q45OUcQK+7KnQ_u0tvzUyOSXGpQbLSUy+Q@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
==
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121125/49bbc51a/attachment.html
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: not available
Url: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20121125/49bbc51a/attachment.pl
More information about the NumPy-Discussion
mailing list