[Numpy-discussion] casting integers to reals

Gael Varoquaux gael.varoquaux at normalesup.org
Thu Feb 26 17:55:10 EST 2009


On Thu, Feb 26, 2009 at 05:53:28PM -0500, Gideon Simpson wrote:
> I want to do:

> numpy.float(numpy.arange(0, 10))

> but get the error:

> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: only length-1 arrays can be converted to Python scalars

> How should I do this?

nump.arange(0, 10.astype(numpy.float)

but in this special case you can do:

numpy.arange(0., 10.)

Gaël



More information about the NumPy-Discussion mailing list