Strange numpy.argmax behavior on object arrays in numpy 1.0.
I recently upgraded to numpy 1.0 from 1.0b5. I noticed that numpy.argmaxbehavior is very strange on object arrays. See below: (Pdb) numpy.__version__ '1.0' (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object)) 0 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=int)) 1 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object), axis=0) 0 I would expect the argmax to behave the same on the dtype=int and dtype=object examples but it doesn't. Am I missing some subtelty or is this just a bug? 1.0 is the most recent version, right? --Tom ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
On 10/29/06, Tom Denniston
I recently upgraded to numpy 1.0 from 1.0b5. I noticed that numpy.argmaxbehavior is very strange on object arrays. See below:
(Pdb) numpy.__version__ '1.0' (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object)) 0 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=int)) 1 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object), axis=0) 0
I would expect the argmax to behave the same on the dtype=int and dtype=object examples but it doesn't. Am I missing some subtelty or is this just a bug? 1.0 is the most recent version, right?
Suppose In [22]: array([1,[2,3]], dtype=object) Out[22]: array([1, [2, 3]], dtype=object) How would you compare the elements? In [27]: 2 < [0,0] Out[27]: True In [28]: [0,0] > 2 Out[28]: True Compares memory locations? In [28]: [2] < [0,0] Out[28]: False Lexical ordering? I don't know how python interprets these things. That said, I suspect your example should behave better, but it might give strange results sometimes anyway. Chuck ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Oh. My mistake. I thought I had an array of 2 objects which were ints. I
actually had an array of one list of 2 ints. It works properly if I
construct the array properly.
In [14]: a = numpy.empty((2), dtype=object)
In [15]: a[0:]=[2,3]
In [16]: a
Out[16]: array([2, 3], dtype=object)
In [17]: a.shape
Out[17]: (2,)
In [18]: a[0]
Out[18]: 2
In [19]: a[1]
Out[19]: 3
In [20]: numpy.argmax(a)
Out[20]: 1
On 10/29/06, Charles R Harris
On 10/29/06, Tom Denniston
wrote: I recently upgraded to numpy 1.0 from 1.0b5. I noticed that numpy.argmax behavior is very strange on object arrays. See below:
(Pdb) numpy.__version__ '1.0' (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object)) 0 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=int)) 1 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object), axis=0) 0
I would expect the argmax to behave the same on the dtype=int and dtype=object examples but it doesn't. Am I missing some subtelty or is this just a bug? 1.0 is the most recent version, right?
Suppose
In [22]: array([1,[2,3]], dtype=object) Out[22]: array([1, [2, 3]], dtype=object)
How would you compare the elements?
In [27]: 2 < [0,0] Out[27]: True
In [28]: [0,0] > 2 Out[28]: True
Compares memory locations?
In [28]: [2] < [0,0] Out[28]: False
Lexical ordering?
I don't know how python interprets these things. That said, I suspect your example should behave better, but it might give strange results sometimes anyway.
Chuck
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
On 10/29/06, Tom Denniston
Oh. My mistake. I thought I had an array of 2 objects which were ints. I actually had an array of one list of 2 ints. It works properly if I construct the array properly.
I think there is actually a bug here: In [61]: sort(array([3,2], dtype=object)) Out[61]: array([2, 3], dtype=object) In [62]: argmax(array([2,3], dtype=object)) Out[62]: 0 See, the sort works fine. I suspect argmax is using the wrong comparison function. I was just pointing out that sometimes it is hard to know what is going on with objects. Chuck ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Yes I definately agree about the latter!
On 10/29/06, Charles R Harris
On 10/29/06, Tom Denniston
wrote: Oh. My mistake. I thought I had an array of 2 objects which were ints. I actually had an array of one list of 2 ints. It works properly if I construct the array properly.
I think there is actually a bug here:
In [61]: sort(array([3,2], dtype=object)) Out[61]: array([2, 3], dtype=object)
In [62]: argmax(array([2,3], dtype=object)) Out[62]: 0
See, the sort works fine. I suspect argmax is using the wrong comparison function. I was just pointing out that sometimes it is hard to know what is going on with objects.
Chuck
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Tom Denniston wrote:
I recently upgraded to numpy 1.0 from 1.0b5. I noticed that numpy.argmax behavior is very strange on object arrays. See below:
(Pdb) numpy.__version__ '1.0' (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object)) 0 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=int)) 1 (Pdb) numpy.argmax(numpy.array([2, 3], dtype=object), axis=0) 0
I would expect the argmax to behave the same on the dtype=int and dtype=object examples but it doesn't. Am I missing some subtelty or is this just a bug? 1.0 is the most recent version, right? This is a bug. I've fixed in in SVN. Thanks for the test.
-Travis ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
participants (3)
-
Charles R Harris
-
Tom Denniston
-
Travis Oliphant