Re: [Numpy-discussion] Apply a function to all indices

2010-02-28 Thread Ernest Adrogué
28/02/10 @ 01:56 (-0500), thus spake David Warde-Farley: > On 26-Feb-10, at 8:12 AM, Ernest Adrogué wrote: > > > Thanks for the tip. I didn't know that... > > Also, frompyfunc appears to crash python when the last argument is 0: > > > > In [9]: func=np.frompyfunc(lambda x: x, 1, 0) > > > > In [10]

Re: [Numpy-discussion] Apply a function to all indices

2010-02-27 Thread David Warde-Farley
On 26-Feb-10, at 8:12 AM, Ernest Adrogué wrote: > Thanks for the tip. I didn't know that... > Also, frompyfunc appears to crash python when the last argument is 0: > > In [9]: func=np.frompyfunc(lambda x: x, 1, 0) > > In [10]: func(np.arange(5)) > Violació de segment > > This with Python 2.5.5, Nu

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
26/02/10 @ 13:51 (+0200), thus spake Pauli Virtanen: > pe, 2010-02-26 kello 12:43 +0100, Ernest Adrogué kirjoitti: > [clip] > > Or if you want to produce a different array of the same shape > > as the original, then you probably need a vectorised function. > > > > def myfunc(x): > > print 'myf

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
26/02/10 @ 13:31 (+0100), thus spake Ole Streicher: > Hello Ernest, > > Ernest Adrogué writes: > > It depends on what exactly you want to do. If you just want > > to iterate over the array, try something liks this > > for element in a[a > 0.8]: > > myfunc(element) > > No; I need to iterate o

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ole Streicher
Hello Ernest, Ernest Adrogué writes: > It depends on what exactly you want to do. If you just want > to iterate over the array, try something liks this > for element in a[a > 0.8]: > myfunc(element) No; I need to iterate over the *indices*, not over the elements. a = numpy.random.random((

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Pauli Virtanen
pe, 2010-02-26 kello 12:43 +0100, Ernest Adrogué kirjoitti: [clip] > Or if you want to produce a different array of the same shape > as the original, then you probably need a vectorised function. > > def myfunc(x): > print 'myfunc of', x > if x > 0.8: > return x + 2 > els

Re: [Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ernest Adrogué
Hi, 26/02/10 @ 11:23 (+0100), thus spake Ole Streicher: > Hi, > > I want to apply a function to all indices of an array that fullfill a > certain condition. > > What I tried: > > -8< > import numpy > > def myfunc(x): > print 'myfunc of', x

[Numpy-discussion] Apply a function to all indices

2010-02-26 Thread Ole Streicher
Hi, I want to apply a function to all indices of an array that fullfill a certain condition. What I tried: -8< import numpy def myfunc(x): print 'myfunc of', x a = numpy.random.random((2,3,4)) numpy.apply_along_axis(myfunc, 0, numpy.where