[Numpy-discussion] retrieving type objects for void array-scalar objects

N. Volbers mithrandir42 at web.de
Fri Feb 3 13:06:08 CST 2006


Hello everyone!

I think I have finally understood the 'void array-scalar object', but now I need some help me with the following. Assume I have an array, e.g.  

>>> dtype = numpy.dtype({'names': ['name', 'weight'],'formats': ['U30', 'f4']})
>>> a = numpy.array([(u'Bill', 71.2), (u'Fred', 94.3)], dtype=dtype)

and this array is displayed in a graphical list. When the user modifies a value in the GUI, the value, which is a string, needs to be converted to the appropriate type, which in this example might either be a unicode string for the 'name' _or_ a float for the 'weight'.

If the row already exists, I can get the type object easily:

>>> my_type = type(ds.array['weight'][0])
<type 'float32_arrtype'>

and using this type object, I can convert the string

>>> value = my_type(user_value)

Is there some way to retrieve the type object directly from the array (not using any existing row) using only the name of the item?  I have checked the dtype attribute, but I could only get the character representation for the item types (e.g. 'f4').

Any help would be appreciated,

Niklas Volbers.











More information about the Numpy-discussion mailing list