[Numpy-discussion] Nonzero behaving strangely?

santhu kumar mesanthu@gmail....
Thu Mar 17 21:10:21 CDT 2011


Thanks a lot for the replies.
I have misunderstood the output. When it says (array[0]), i thought it did
not find anything as opposed to the zeroth row. (Still getting used to
matlab indexing i guess !! ) .. Sorry !!

Thanks a lot for the sugestions though, Would keep it in mind ..

From: santhu kumar <mesanthu@gmail.com>
> Subject: [Numpy-discussion] Nonzero behaving strangely?
> To: numpy-discussion@scipy.org
> Message-ID:
>        <AANLkTinnFb6cbRUDb3GuaQsMCoq0DKyWQy77j9HmMjxf@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello all,
>
> I am new to Numpy. I used to program before in matlab and am getting used
> to
> Numpy.
>
> I have a array like:
> res
> array([[ 33.35053669,  49.4615004 ,  44.27631299,   1.        ,   2.
> ],
>       [ 32.84263059,  50.24752036,  43.92291659,   1.        ,   0.
> ],
>       [ 33.68999668,  48.90554673,  43.51746687,   1.        ,   0.
> ],
>       [ 34.11564931,  49.77487763,  44.83843076,   1.        ,   0.
> ],
>       [ 32.4641859 ,  48.65469145,  45.09300791,   1.        ,   3.
> ],
>       [ 32.15428526,  49.26922262,  45.92959026,   1.        ,   0.
> ],
>       [ 31.23860825,  48.21824628,  44.30816331,   1.        ,   0.
> ],
>       [ 30.71171138,  47.45600573,  44.9282456 ,   1.        ,   0.
> ],
>       [ 30.53843426,  49.07713258,  44.20899822,   1.        ,   0.
> ],
>       [ 31.54722284,  47.61953925,  42.95235178,   1.        ,   0.
> ],
>       [ 32.44334635,  48.10500653,  42.51103537,   1.        ,   0.
> ],
>       [ 31.77269609,  46.53603145,  43.06468455,   1.        ,   0.
> ],
>       [ 30.1820843 ,  47.80819604,  41.77667819,   1.        ,   0.
> ],
>       [ 30.78652668,  46.82907769,  40.38586451,   1.        ,   0.
> ],
>       [ 30.05963091,  46.84268609,  39.54583693,   1.        ,   0.
> ],
>       [ 31.75239177,  47.22768463,  40.00717713,   1.        ,   0.
> ],
>       [ 30.94617127,  45.76986265,  40.68226643,   1.        ,   0.
> ],
>       [ 33.20069679,  47.42127403,  45.66738249,   1.        ,   0.
> ],
>       [ 34.39608116,  47.25481126,  45.4438599 ,   1.        ,   0.
> ]])
>
> The array is 19X5.
> When I do:
> nid = (res[:,4]==2).nonzero()
> nid tuple turns out to be empty. But the very first row satisfies the
> criteria.
>
> nid = (res[:,4]==3).nonzero(), works out and finds the 5th row.
>
> Am i doing something wrong?
> I basically want to find the rows whose fifth coloumn(4th in numpy matrix
> format) is 2.
>
> Any suggestions?
> Thanks
> Santhosh
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110317/2f46f2c1/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Thu, 17 Mar 2011 23:19:42 +0100
> From: Matthieu Brucher <matthieu.brucher@gmail.com>
> Subject: Re: [Numpy-discussion] Nonzero behaving strangely?
> To: Discussion of Numerical Python <numpy-discussion@scipy.org>
> Message-ID:
>        <AANLkTimEipz6cPaMauY2f_0MpJwkWjdWe0OC4WM-LpOu@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> Did you try np.where(res[:,4]==2) ?
>
> Matthieu
>
> 2011/3/17 santhu kumar <mesanthu@gmail.com>
>
> > Hello all,
> >
> > I am new to Numpy. I used to program before in matlab and am getting used
> > to Numpy.
> >
> > I have a array like:
> > res
> > array([[ 33.35053669,  49.4615004 ,  44.27631299,   1.        ,   2.
> > ],
> >        [ 32.84263059,  50.24752036,  43.92291659,   1.        ,   0.
> > ],
> >        [ 33.68999668,  48.90554673,  43.51746687,   1.        ,   0.
> > ],
> >        [ 34.11564931,  49.77487763,  44.83843076,   1.        ,   0.
> > ],
> >        [ 32.4641859 ,  48.65469145,  45.09300791,   1.        ,   3.
> > ],
> >        [ 32.15428526,  49.26922262,  45.92959026,   1.        ,   0.
> > ],
> >        [ 31.23860825,  48.21824628,  44.30816331,   1.        ,   0.
> > ],
> >        [ 30.71171138,  47.45600573,  44.9282456 ,   1.        ,   0.
> > ],
> >        [ 30.53843426,  49.07713258,  44.20899822,   1.        ,   0.
> > ],
> >        [ 31.54722284,  47.61953925,  42.95235178,   1.        ,   0.
> > ],
> >        [ 32.44334635,  48.10500653,  42.51103537,   1.        ,   0.
> > ],
> >        [ 31.77269609,  46.53603145,  43.06468455,   1.        ,   0.
> > ],
> >        [ 30.1820843 ,  47.80819604,  41.77667819,   1.        ,   0.
> > ],
> >        [ 30.78652668,  46.82907769,  40.38586451,   1.        ,   0.
> > ],
> >        [ 30.05963091,  46.84268609,  39.54583693,   1.        ,   0.
> > ],
> >        [ 31.75239177,  47.22768463,  40.00717713,   1.        ,   0.
> > ],
> >        [ 30.94617127,  45.76986265,  40.68226643,   1.        ,   0.
> > ],
> >        [ 33.20069679,  47.42127403,  45.66738249,   1.        ,   0.
> > ],
> >        [ 34.39608116,  47.25481126,  45.4438599 ,   1.        ,   0.
> > ]])
> >
> > The array is 19X5.
> > When I do:
> > nid = (res[:,4]==2).nonzero()
> > nid tuple turns out to be empty. But the very first row satisfies the
> > criteria.
> >
> > nid = (res[:,4]==3).nonzero(), works out and finds the 5th row.
> >
> > Am i doing something wrong?
> > I basically want to find the rows whose fifth coloumn(4th in numpy matrix
> > format) is 2.
> >
> > Any suggestions?
> > Thanks
> > Santhosh
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
>
>
> --
> Information System Engineer, Ph.D.
> Blog: http://matt.eifelle.com
> LinkedIn: http://www.linkedin.com/in/matthieubrucher
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110317/3b48f06c/attachment-0001.html
>
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 17 Mar 2011 17:27:19 -0500
> From: Warren Weckesser <warren.weckesser@enthought.com>
> Subject: Re: [Numpy-discussion] Nonzero behaving strangely?
> To: Discussion of Numerical Python <numpy-discussion@scipy.org>
> Message-ID:
>        <AANLkTi=SHeodTbnqe07Gco1F4wYeQzOOjTyi6n-qia-g@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> On Thu, Mar 17, 2011 at 5:17 PM, santhu kumar <mesanthu@gmail.com> wrote:
>
> > Hello all,
> >
> > I am new to Numpy. I used to program before in matlab and am getting used
> > to Numpy.
> >
> > I have a array like:
> > res
> > array([[ 33.35053669,  49.4615004 ,  44.27631299,   1.        ,   2.
> > ],
> >        [ 32.84263059,  50.24752036,  43.92291659,   1.        ,   0.
> > ],
> >        [ 33.68999668,  48.90554673,  43.51746687,   1.        ,   0.
> > ],
> >        [ 34.11564931,  49.77487763,  44.83843076,   1.        ,   0.
> > ],
> >        [ 32.4641859 ,  48.65469145,  45.09300791,   1.        ,   3.
> > ],
> >        [ 32.15428526,  49.26922262,  45.92959026,   1.        ,   0.
> > ],
> >        [ 31.23860825,  48.21824628,  44.30816331,   1.        ,   0.
> > ],
> >        [ 30.71171138,  47.45600573,  44.9282456 ,   1.        ,   0.
> > ],
> >        [ 30.53843426,  49.07713258,  44.20899822,   1.        ,   0.
> > ],
> >        [ 31.54722284,  47.61953925,  42.95235178,   1.        ,   0.
> > ],
> >        [ 32.44334635,  48.10500653,  42.51103537,   1.        ,   0.
> > ],
> >        [ 31.77269609,  46.53603145,  43.06468455,   1.        ,   0.
> > ],
> >        [ 30.1820843 ,  47.80819604,  41.77667819,   1.        ,   0.
> > ],
> >        [ 30.78652668,  46.82907769,  40.38586451,   1.        ,   0.
> > ],
> >        [ 30.05963091,  46.84268609,  39.54583693,   1.        ,   0.
> > ],
> >        [ 31.75239177,  47.22768463,  40.00717713,   1.        ,   0.
> > ],
> >        [ 30.94617127,  45.76986265,  40.68226643,   1.        ,   0.
> > ],
> >        [ 33.20069679,  47.42127403,  45.66738249,   1.        ,   0.
> > ],
> >        [ 34.39608116,  47.25481126,  45.4438599 ,   1.        ,   0.
> > ]])
> >
> > The array is 19X5.
> > When I do:
> > nid = (res[:,4]==2).nonzero()
> > nid tuple turns out to be empty. But the very first row satisfies the
> > criteria.
> >
> > nid = (res[:,4]==3).nonzero(), works out and finds the 5th row.
> >
> > Am i doing something wrong?
> > I basically want to find the rows whose fifth coloumn(4th in numpy matrix
> > format) is 2.
> >
> >
>
> Are you sure the value of res[0,4] is *exactly* 2.0, and not something
> like,
> say, 2.0000000000000009?
>
> Warren
>
>
> > Any suggestions?
> > Thanks
> > Santhosh
> >
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
> >
> >
>
>
>
>
> ------------------------------
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> End of NumPy-Discussion Digest, Vol 54, Issue 75
> ************************************************
>



-- 
bye and take care
santhu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110317/a40dee8d/attachment-0001.html 


More information about the NumPy-Discussion mailing list