Re: [Numpy-discussion] Structured array sorting

2010-01-18 Thread Thomas Robitaille


Warren Weckesser-3 wrote:
 
 Looks like 'sort' is not handling endianess of the column data 
 correctly.  If you change the type of the floating point data to 'f8', 
 the sort works.
 

Thanks for identifying the issue - should I submit a bug report?

Thomas
-- 
View this message in context: 
http://old.nabble.com/Structured-array-sorting-tp27200785p27210615.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Structured array sorting

2010-01-18 Thread Charles R Harris
On Mon, Jan 18, 2010 at 6:39 AM, Thomas Robitaille 
thomas.robitai...@gmail.com wrote:



 Warren Weckesser-3 wrote:
 
  Looks like 'sort' is not handling endianess of the column data
  correctly.  If you change the type of the floating point data to 'f8',
  the sort works.
 

 Thanks for identifying the issue - should I submit a bug report?


Yes.

Chuck
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Structured array sorting

2010-01-17 Thread Thomas Robitaille
I am having trouble sorting a structured array - in the example below, sorting 
by the first column (col1) seems to work, but not sorting by the second column 
(col2). Is this a bug?

I am using numpy svn r8071 on MacOS 10.6.

Thanks for any help,

Thomas

Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type help, copyright, credits or license for more information.
 import numpy as np
 data = np.array([('a ', 2.), ('b', 4.), ('d', 3.), ('c', 1.)],
... dtype=[('col1', '|S5'), ('col2', 'f8')])
 
 data
array([('a ', 2.0), ('b', 4.0), ('d', 3.0), ('c', 1.0)], 
  dtype=[('col1', '|S5'), ('col2', 'f8')])
 data.sort(order=['col1'])
 data
array([('a ', 2.0), ('b', 4.0), ('c', 1.0), ('d', 3.0)], 
  dtype=[('col1', '|S5'), ('col2', 'f8')])
 data.sort(order=['col2'])
 data
array([('a ', 2.0), ('d', 3.0), ('b', 4.0), ('c', 1.0)], 
  dtype=[('col1', '|S5'), ('col2', 'f8')])


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Structured array sorting

2010-01-17 Thread Warren Weckesser
Looks like 'sort' is not handling endianess of the column data 
correctly.  If you change the type of the floating point data to 'f8', 
the sort works.   Here's another example with short ints:

-
In [137]: z = np.array([(0,),(258,),(256,),(1,),(255,)], 
dtype=[('num','i2')])

In [138]: z.sort(order='num')

In [139]: z
Out[139]:
array([(0,), (1,), (255,), (256,), (258,)],
  dtype=[('num', 'i2')])

In [140]: z = np.array([(0,),(258,),(256,),(1,),(255,)], 
dtype=[('num','i2')])

In [141]: z.sort(order='num')

In [142]: z
Out[142]:
array([(255,), (0,), (256,), (1,), (258,)],
  dtype=[('num', 'i2')])

In [143]: np.__version__
Out[143]: '1.3.0'
-

Sorting works as expected with a simple array of short ints:

-
In [152]: w = np.array([0,258, 3, 255], dtype='i2')

In [153]: w.data.__str__()
Out[153]: '\x00\x00\x02\x01\x03\x00\xff\x00'

In [154]: w.sort()

In [155]: w
Out[155]: array([  0,   3, 255, 258], dtype=int16)

In [156]: w = np.array([0,258, 3, 255], dtype='i2')

In [157]: w.data.__str__()
Out[157]: '\x00\x00\x01\x02\x00\x03\x00\xff'

In [158]: w.sort()

In [159]: w
Out[159]: array([  0,   3, 255, 258], dtype=int16)
-

(This is on a Mac, running OSX 10.5 with python 2.5.4.)

Warren



Thomas Robitaille wrote:
 I am having trouble sorting a structured array - in the example below, 
 sorting by the first column (col1) seems to work, but not sorting by the 
 second column (col2). Is this a bug?

 I am using numpy svn r8071 on MacOS 10.6.

 Thanks for any help,

 Thomas

 Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51) 
 [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
 Type help, copyright, credits or license for more information.
   
 import numpy as np
 data = np.array([('a ', 2.), ('b', 4.), ('d', 3.), ('c', 1.)],
 
 ... dtype=[('col1', '|S5'), ('col2', 'f8')])
   
 data
 
 array([('a ', 2.0), ('b', 4.0), ('d', 3.0), ('c', 1.0)], 
   dtype=[('col1', '|S5'), ('col2', 'f8')])
   
 data.sort(order=['col1'])
 data
 
 array([('a ', 2.0), ('b', 4.0), ('c', 1.0), ('d', 3.0)], 
   dtype=[('col1', '|S5'), ('col2', 'f8')])
   
 data.sort(order=['col2'])
 data
 
 array([('a ', 2.0), ('d', 3.0), ('b', 4.0), ('c', 1.0)], 
   dtype=[('col1', '|S5'), ('col2', 'f8')])


 ___
 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