[Numpy-discussion] field names on numpy arrays
D2Hitman
j.m.girven at warwick.ac.uk
Wed Jun 3 11:06:12 EDT 2009
Hi,
I would like to have an object/class that acts like array of floats such as:
a_array = numpy.array([[0.,1.,2.,3.,4.],[1.,2.,3.,4.,5.]])
but i would like to be able to slice this array by some header dictionary:
header_dict = {'a':0,'b':1,'c':2,'d':3,'e':4}
such that i could use a_array['a'],
which would get slice=header_dict['a'],
slices a_array[:,slice]
and return it.
I understand record arrays such as:
a_array =
np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'),('b','f'),('c','f'),('d','f'),('e','f')])
do this with field names.
a_array['a'] = array([ 0., 1.], dtype=float32)
however i seem to lose simple operations such as multiplication (a_array*2)
or powers (a_array**2).
Is there something that does this? Or how would i go about creating an
object/class that inherits all properties from numpy.array, but adds in a
header to select columns?
a_array = MyArray([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],
header=['a','b','c','d','e'])
Thanks,
Jon.
--
View this message in context: http://www.nabble.com/field-names-on-numpy-arrays-tp23852413p23852413.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list