[Numpy-discussion] printing structured arrays
Mon Mar 8 14:00:29 CST 2010
On Mar 8, 2010, at 1:55 PM, Tim Michelsen wrote:
> I am also looking into the convertsion from strcutured arrays to ndarray.
>> I've just started playing with numpy and have noticed that when printing
>> a structured array that the output is not nicely formatted. Is there a
>> way to make the formatting look the same as it does for an unstructured
>> Output is:
>> ### ndarray
>> [[ 1. 2. ]
>> [ 3. 4.1]]
>> ### structured array
>> [(1.0, 2.0) (3.0, 4.0999999999999996)]
> How could we make this structured array look like the above shown
> ndarray with shape (2, 2)?
if you're 100% sure all your fields have the same dtype (float), ``a.view((float,2))`` is the simplest. Note the tuple (dtype, len(a.dtype.names)).
More information about the NumPy-Discussion