[Numpy-discussion] casting integers to reals

Gael Varoquaux gael.varoquaux@normalesup....
Thu Feb 26 16:55:10 CST 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