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

Alan Isaac aisaac at american.edu
Fri Oct 5 15:21:31 EDT 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