[SciPy-User] best way to convert a structured array to a float view (again)
Vincent Davis
vincent at vincentdavis.net
Sat Jun 5 00:16:56 EDT 2010
2010/6/4 Stéfan van der Walt <stefan at sun.ac.za>:
> On 4 June 2010 08:55, Skipper Seabold <jsseabold at gmail.com> wrote:
>> Say I have the following arrays that I want to view as/cast to plain
>> ndarrays with float dtype
>>
>> import numpy as np
>> arr = np.array([(24,),(24,),(24,),(24,),(24,)], dtype=[("var1",int)])
>>
>> arr2 = np.array([(24,4.5),(24,4.5),(24,4.5),(24,4.5),(24,4.5)],
>> dtype=[("var1",int),("var2",float)])
How about this,
arr2 = np.column_stack((arr[col] for col in arr.dtype.names))
>
> How about
>
> arr.view(int).astype(float)
>
> Stéfan
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list