[Numpy-discussion] dtype confusion

Jan Strube curiousjan@gmail....
Sun Mar 25 06:09:11 CDT 2007

There seems to be a fundamental lack of understanding on my behalf when it
comes to dtypes and record arrays.
Please consider the following snippet:

import numpy as N
newtype = N.dtype([('x', N.float64), ('y', N.float64), ('z', N.float64)])
a = N.random.random((100,3))
b = N.column_stack([a['x'].ravel(), a['y'].ravel(), a['z'].ravel()])
b.dtype = newtype
--> ValueError: new type not compatible with array.

I don't understand two things about this:
i) the shape of a changes from (100,3) to (100,1) after assigning the dtype.
ii) the shape of b is obviously (100,3), so why can't I assign the new

Could someone please point out the flaws in this approach?
Thanks much,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070325/86ac124c/attachment.html 

More information about the Numpy-discussion mailing list