[SciPy-User] best way to convert a structured array to a float view (again)

Stéfan van der Walt stefan@sun.ac...
Fri Jun 4 18:19:29 CDT 2010


On 4 June 2010 08:55, Skipper Seabold <jsseabold@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

arr.view(int).astype(float)

Stéfan


More information about the SciPy-User mailing list