[Numpy-discussion] dtype.type for structured arrays
Travis Oliphant
oliphant@enthought....
Fri Aug 6 19:07:21 CDT 2010
On Jul 24, 2010, at 2:42 PM, Thomas Robitaille wrote:
> Hi,
>
> If I create a structured array with vector columns:
>
>>>> array = np.array(zip([[1,2],[1,2],[1,3]]),dtype=[('a',float,2)])
>
> then examine the type of the column, I get:
>
>>>> array.dtype[0]
> dtype(('float64',(2,)))
>
> Then, if I try and view the numerical type, I see:
>
>>>> array.dtype[0].type
> <type 'numpy.void'>
>
> I have to basically do
>
>>>> array.dtype[0].subdtype[0]
> dtype('float64')
>
> to get what I need. I seem to remember that this used not to be the case, and that even for vector columns, one could access array.dtype[0].type to get the numerical type. Is this a bug, or deliberate?
>
This looks the same as I remember it. The dtype is a structured array with the filed name 'a' having an element which is a vector of floats. As a result, the first dtype[0] extracts the vector of floats dtype. This must be type "void" because it is a vector of floats. To get to the underlying type, you have to do what you did. I don't see how it would have worked another way in the past.
-Travis
> Thanks,
>
> Thomas
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
---
Travis Oliphant
Enthought, Inc.
oliphant@enthought.com
1-512-536-1057
http://www.enthought.com
More information about the NumPy-Discussion
mailing list