[Numpy-discussion] howto convert float array to array of integers

Alan Isaac aisaac@american....
Fri Oct 5 14:21:31 CDT 2007


On Fri, 05 Oct 2007, dmitrey wrote:
> I have an array like array([ 1.,  0.,  2.,  -10.])
> what is most efficient (i.e. fastest) way to convert the one to array of 
> integers? 
> array([ 1,  0,  2,  -10])

Use ``astype``.

Cheers,
Alan Isaac



>>> import numpy as N
>>> x = N.array([1,2,3],dtype='float')
>>> x
array([ 1.,  2.,  3.])
>>> x.astype('int')
array([1, 2, 3])
>>>




More information about the Numpy-discussion mailing list