Re: [Numpy-discussion] numpy where function on different sized arrays
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
Subject: Re: [Numpy-discussion] numpy where function on different sized arrays To: Discussion of Numerical Python Message-ID: 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.
participants (1)
-
Siegfried Gonzi