Re: [Numpy-discussion] How do I ensure numpy headers are present in setup.py?

2010-04-02 Thread josef . pktd
On Fri, Apr 2, 2010 at 11:45 PM, Chris Colbert wrote: > > > On Fri, Apr 2, 2010 at 3:03 PM, Erik Tollerud > wrote: > you could try something like this (untested): > if __name__ == '__main__': >     try: >         import numpy >     except ImportError: >         import subprocess >         subproc

Re: [Numpy-discussion] How do I ensure numpy headers are present in setup.py?

2010-04-02 Thread Chris Colbert
On Fri, Apr 2, 2010 at 3:03 PM, Erik Tollerud wrote: you could try something like this (untested): if __name__ == '__main__': try: import numpy except ImportError: import subprocess subprocess.check_call(['easy_install', 'numpy']) # will except if call fails _

Re: [Numpy-discussion] How do I get element on axis 1

2010-04-02 Thread Vishal Rana
Thanks Warren! On Fri, Apr 2, 2010 at 2:46 PM, Warren Weckesser < warren.weckes...@enthought.com> wrote: > Vishal Rana wrote: > > Hi, > > > > I know its easy, but I am not just getting it... > > > > How do I get last element on axis=1 for: > > > > a = array([[ 0, 1, 2, 3, 4], > >[ 5,

Re: [Numpy-discussion] How do I get element on axis 1

2010-04-02 Thread Warren Weckesser
Vishal Rana wrote: > Hi, > > I know its easy, but I am not just getting it... > > How do I get last element on axis=1 for: > > a = array([[ 0, 1, 2, 3, 4], >[ 5, 6, 7, 8, 9], >[10, 11, 12, 13, 14], >[15, 16, 17, 18, 19], >[20, 21, 22, 23, 24]]) > > Expected:

[Numpy-discussion] How do I get element on axis 1

2010-04-02 Thread Vishal Rana
Hi, I know its easy, but I am not just getting it... How do I get last element on axis=1 for: a = array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]) Expected: array([4, 9, 14, 19, 24]) Thanks Vishal

Re: [Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread eat
Shailendra gmail.com> writes: > > Well, this is just a toy problem. argmax represent a method which will > give me a index in x[cond] . And for the case of multiple value my > requirement is fine with getting any "max" index. OK. My concern seems to be needless then. BTW, does this current th

Re: [Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread Shailendra
Well, this is just a toy problem. argmax represent a method which will give me a index in x[cond] . And for the case of multiple value my requirement is fine with getting any "max" index. Thanks, Shailendra On Fri, Apr 2, 2010 at 3:00 PM, eat wrote: > Shailendra gmail.com> writes: > >> >> I fo

Re: [Numpy-discussion] Applying formula to all in an array which hasvalue from previous

2010-04-02 Thread Vishal Rana
I get AttributeError: 'NoneType' object has no attribute 'accumulate' for the call vecfun.ufunc.accumulate(np.array([0, 1, 2, 3])) It works fine if I make a dummy call to vecfun before! Any idea for this behavior? Thanks Vishal Rana On Mon, Mar 29, 2010 at 4:07 AM, Nadav Horesh wrote: > The ge

Re: [Numpy-discussion] How do I ensure numpy headers are present in setup.py?

2010-04-02 Thread Robert Kern
On Fri, Apr 2, 2010 at 13:03, Erik Tollerud wrote: > I am writing a setup.py file for a package that will use cython with > numpy integration.  This of course requires the numpy header files, > which I am including by using numpy.get_includes in the setup.py file > below.  The problem is for users

[Numpy-discussion] How do I ensure numpy headers are present in setup.py?

2010-04-02 Thread Erik Tollerud
I am writing a setup.py file for a package that will use cython with numpy integration. This of course requires the numpy header files, which I am including by using numpy.get_includes in the setup.py file below. The problem is for users that have not installed numpy before installing this packag

Re: [Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread eat
Shailendra gmail.com> writes: > > I forgot to mention that i wanted this to work for general shape. So i > modified it little bit > > >>> x = array([[1,2,3,4,5], [6,7,8,7,6], [1,2,3,4,5]]) > >>> cond = (x > 5) > >>> loc= where(cond) > >>> arg_max=argmax(x[cond]) > >>> x[tuple([e[arg_max] for e

Re: [Numpy-discussion] Asymmetry in Chebyshev.deriv v. Chebyshev.integ

2010-04-02 Thread David Goldsmith
On Fri, Apr 2, 2010 at 10:46 AM, Charles R Harris wrote: > On Fri, Apr 2, 2010 at 11:27 AM, David Goldsmith > wrote: > >> Also: >> >> >>> c.deriv(0) >> Chebyshev([ 1.], [-1., 1.]) >> >>> c.integ(0) >> >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 441, in int

Re: [Numpy-discussion] Asymmetry in Chebyshev.deriv v. Chebyshev.integ

2010-04-02 Thread David Goldsmith
On Fri, Apr 2, 2010 at 10:42 AM, Charles R Harris wrote: > > On Thu, Apr 1, 2010 at 7:42 PM, David Goldsmith > wrote: > >> >>> np.version.version >> '1.4.0' >> >>> c = np.polynomial.chebyshev.Chebyshev(1) >> >>> c.deriv(1.0) >> Chebyshev([ 0.], [-1., 1.]) >> >>> c.integ(1.0) >> Traceback (most

Re: [Numpy-discussion] Asymmetry in Chebyshev.deriv v. Chebyshev.integ

2010-04-02 Thread Charles R Harris
On Fri, Apr 2, 2010 at 11:27 AM, David Goldsmith wrote: > On Thu, Apr 1, 2010 at 6:42 PM, David Goldsmith > wrote: > >> >>> np.version.version >> '1.4.0' >> >>> c = np.polynomial.chebyshev.Chebyshev(1) >> >>> c.deriv(1.0) >> Chebyshev([ 0.], [-1., 1.]) >> >>> c.integ(1.0) >> Traceback (most rece

Re: [Numpy-discussion] Asymmetry in Chebyshev.deriv v. Chebyshev.integ

2010-04-02 Thread Charles R Harris
On Thu, Apr 1, 2010 at 7:42 PM, David Goldsmith wrote: > >>> np.version.version > '1.4.0' > >>> c = np.polynomial.chebyshev.Chebyshev(1) > >>> c.deriv(1.0) > Chebyshev([ 0.], [-1., 1.]) > >>> c.integ(1.0) > Traceback (most recent call last): > File "", line 1, in > File "", line 441, in inte

Re: [Numpy-discussion] Asymmetry in Chebyshev.deriv v. Chebyshev.integ

2010-04-02 Thread David Goldsmith
On Thu, Apr 1, 2010 at 6:42 PM, David Goldsmith wrote: > >>> np.version.version > '1.4.0' > >>> c = np.polynomial.chebyshev.Chebyshev(1) > >>> c.deriv(1.0) > Chebyshev([ 0.], [-1., 1.]) > >>> c.integ(1.0) > Traceback (most recent call last): > File "", line 1, in > File "", line 441, in inte

[Numpy-discussion] List of indices

2010-04-02 Thread Shailendra
Hi All, >>> x=arange(10) >>> indices=[(1,),(2,)] >>> x[indices] Traceback (most recent call last): File "", line 1, in IndexError: unsupported iterator index But following works. >>> x=x.reshape(5,2) >>> x array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]) >>> indices

Re: [Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread Shailendra
I forgot to mention that i wanted this to work for general shape. So i modified it little bit >>> x = array([[1,2,3,4,5], [6,7,8,7,6], [1,2,3,4,5]]) >>> cond = (x > 5) >>> loc= where(cond) >>> arg_max=argmax(x[cond]) >>> x[tuple([e[arg_max] for e in loc])] 8 Thanks for your solution. Shailendra

Re: [Numpy-discussion] Matrix operation.

2010-04-02 Thread Vicente Sole
With A and X being arrays: B=numpy.zeros(A.shape, A.dtype) B[A>0] = X Armando Quoting gerardob : > > Let A be a square matrix of 0's and 1's, and let X be a one dimesional > vector. > The length of X is equal to the number of 1's that A has. > I would like to produce a new matrix B by traversi

Re: [Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread Robert Kern
On Fri, Apr 2, 2010 at 09:31, Shailendra wrote: > Hi All, > I have a following model problem. Let i have a array x > array([[1, 2, 3, 4, 5], >       [6, 7, 8, 7, 6], >       [1, 2, 3, 4, 5]]) > > suppose i apply some cond on it. cond= x>5 x[cond] > array([6, 7, 8, 7, 6]) > > Now, i

[Numpy-discussion] Getting index of array after applying cond

2010-04-02 Thread Shailendra
Hi All, I have a following model problem. Let i have a array >>> x array([[1, 2, 3, 4, 5], [6, 7, 8, 7, 6], [1, 2, 3, 4, 5]]) suppose i apply some cond on it. >>> cond= x>5 >>> x[cond] array([6, 7, 8, 7, 6]) Now, i want to argmax on this >>> max=argmax(x[cond]) >>> max 2 >>> x[cond]

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Ryan May
On Fri, Apr 2, 2010 at 8:31 AM, Robert Kern wrote: > On Fri, Apr 2, 2010 at 08:28, Ryan May wrote: >> On Thu, Apr 1, 2010 at 10:07 PM, Shailendra >> wrote: >>> Hi All, >>> Below is some array behaviour which i think is odd >> a=arange(10) >> a >>> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >

Re: [Numpy-discussion] Matrix operation.

2010-04-02 Thread Shailendra
>>> A=[[1,1,0], ... [1,0,0], ... [0,0,1]] >>> X=[2,9,10,3] >>> import numpy >>> A=numpy.asarray(A) >>> X=numpy.asarray(X) >>> A array([[1, 1, 0], [1, 0, 0], [0, 0, 1]]) >>> X array([ 2, 9, 10, 3]) >>> non_zero=numpy.nonzero(A) >>> non_zero (array([0, 0, 1, 2]), array([0, 1, 0, 2]))

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Shailendra
Thanks everyone for replies/suggestion. It is simple to avoid this problem. But my point that given the behavior of python this behavior seems inconsistent. There could other method provided which could evaluate bool value depending on values stored in the array. Thanks, Shailendra On Fri, Apr 2,

[Numpy-discussion] Matrix operation.

2010-04-02 Thread gerardob
Let A be a square matrix of 0's and 1's, and let X be a one dimesional vector. The length of X is equal to the number of 1's that A has. I would like to produce a new matrix B by traversing the matrix A row by row and: 1- whenever i find a 0, set B in that position to zero. 2- whenever i find a 1,

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Robert Kern
On Fri, Apr 2, 2010 at 08:28, Ryan May wrote: > On Thu, Apr 1, 2010 at 10:07 PM, Shailendra > wrote: >> Hi All, >> Below is some array behaviour which i think is odd > a=arange(10) > a >> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) > b=nonzero(a<0) > b >> (array([], dtype=int32),)

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Ryan May
On Thu, Apr 1, 2010 at 10:07 PM, Shailendra wrote: > Hi All, > Below is some array behaviour which i think is odd a=arange(10) a > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) b=nonzero(a<0) b > (array([], dtype=int32),) if not b[0]: > ...     print 'b[0] is false' > ... > b[0] i

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread josef . pktd
On Fri, Apr 2, 2010 at 10:11 AM, Robert Kern wrote: > On Thu, Apr 1, 2010 at 22:07, Shailendra wrote: >> Hi All, >> Below is some array behaviour which i think is odd > a=arange(10) > a >> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) > b=nonzero(a<0) > b >> (array([], dtype=int32),)

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Robert Kern
On Thu, Apr 1, 2010 at 22:07, Shailendra wrote: > Hi All, > Below is some array behaviour which i think is odd a=arange(10) a > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) b=nonzero(a<0) b > (array([], dtype=int32),) if not b[0]: > ...     print 'b[0] is false' > ... > b[0] is f

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Alan G Isaac
On 4/2/2010 8:29 AM, Nadav Horesh wrote: > In python empty sequences are always equivalent to False, and non-empty to > True. I think that was why the OP objected to this behavior: >>> bool(np.array([0])) False Alan Isaac ___ NumPy

Re: [Numpy-discussion] Is this odd?

2010-04-02 Thread Nadav Horesh
In python empty sequences are always equivalent to False, and non-empty to True. You can use this property or: if len(b) > 0: . Nadav -Original Message- From: numpy-discussion-boun...@scipy.org on behalf of Shailendra Sent: Fri 02-Apr-10 06:07 To: numpy-discussion@scipy.org S