Re: [Numpy-discussion] Arrays of Python Values

2010-07-25 Thread Ian Mallett
Hi,

I've converted all of the code to use record arrays, for a 10-fold speed
boost.  Thanks,

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


Re: [Numpy-discussion] Arrays of Python Values

2010-07-23 Thread Pauli Virtanen
Fri, 23 Jul 2010 01:16:41 -0700, Ian Mallett wrote:
[clip]
 Because I've never used arrays of Python objects (and Googling didn't
 turn up any examples), I'm stuck on how to sort the corresponding array
 in NumPy in the same way.

I doubt you will gain any speed by switching from Python lists to Numpy 
arrays containing Python objects.

 Of course, perhaps I'm just trying something that's absolutely
 impossible, or there's an obviously better way.  I get the feeling that
 having no Python objects in the NumPy array would speed things up even
 more, but I couldn't figure out how I'd handle the different attributes
 (or specifically, how to keep them together during a sort).
 
 What're my options?

One option could be to use structured arrays to store the data, instead 
of Python objects.

-- 
Pauli Virtanen

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


Re: [Numpy-discussion] Arrays of Python Values

2010-07-23 Thread Hans Meine
On Friday 23 July 2010 10:16:41 Ian Mallett wrote:
 self.patches.sort( lambda x,y:cmp(x.residual_radiance,y.residual_radiance),
 reverse=True )

Using sort(key = lambda x: x.residual_radiance) should be faster.

 Because I've never used arrays of Python objects (and Googling didn't turn
 up any examples), I'm stuck on how to sort the corresponding array in NumPy
 in the same way.
 
 Of course, perhaps I'm just trying something that's absolutely impossible,
 or there's an obviously better way.  I get the feeling that having no
 Python objects in the NumPy array would speed things up even more, but [...]

Exactly.

Maybe you can use record arrays?  (Have a look at complex dtypes, i.e. 
struct-like dtypes for arrays.)

Never tried sort on these, but I'd hope that's possible.

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