[SciPy-user] About arrays and objects

Christian K. ckkart@hoc....
Thu Nov 13 14:32:15 CST 2008


Enrique Comesaña Figueroa wrote:
> Hello,
> 
> Is it possible to list a property from an object array without using a
> 'for' loop?
> 
> I've created the array using:
> 
> 
> In [1]: from numpy import *
> 
> In [2]: class nodo:
>   ...:     def __init__(self, pos=0):
>   ...:         self.pos = pos
>   ...:
> 
> In [3]: nodo_array = array ([nodo(1),nodo(2),nodo(3),nodo(4),nodo(5)])
> 
> 
> I want to print the "node_array" using  something like this:
> 
> In [4]: print nodo_array[:].pos
> 
> without using a for loop.
> 
> Is that possible?

Not without subclassing numpy.ndarray I guess. Do you really need a
numpy array or may it be a python list as well? Sublassing a list is
slightly easier but if you insist have a look here:
http://docs.scipy.org/doc/numpy/user/basics.subclassing.html

Christian



More information about the SciPy-user mailing list