[SciPy-user] execute function on an array elementwise
Mon Apr 7 08:33:17 CDT 2008
You could use something like :
res = zeros(X.shape)
res[where(X > 3)] = "some value"
res[where(X <= 3)] = "another value"
Projet PRIMA - Laboratoire LIG
INRIA Grenoble Rhone-Alpes Research Centre
655, Avenue de l'Europe
38330 Montbonnot, France
On 7-Apr-08, at 3:18 PM, Pieter wrote:
> Hi all,
> I guess this is an easy one, but can't seem to find it. Suppose I have
> this function:
> def myFunction(x):
> result = None
> if x > 3:
> result = "some value"
> result = "another value"
> return result
> And I want to run it on an array a:
> b = myFunction(a)
> which then returns an array with "some value" and "another value". I
> could loop over the array, but I guess there's a better way to do
> this? (something like arrayMagic from Matlab if I'm not mistaken.
> thanks a lot,
> Pieter Cogghe
> Ganzendries 186
> 9000 Gent
> 0487 10 14 21
> SciPy-user mailing list
More information about the SciPy-user