[Numpy-discussion] Arrays of Python Values

Hans Meine meine@informatik.uni-hamburg...
Fri Jul 23 07:22:08 CDT 2010

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 [...]


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.


More information about the NumPy-Discussion mailing list