[Numpy-discussion] howto convert float array to array of integers
Christopher Hanley
chanley at stsci.edu
Fri Oct 5 08:20:39 EDT 2007
I usually use the astype method.
>>> import numpy as n
>>> a = n.array([1.,0.,2.,-10.])
>>> a.dtype
dtype('float64')
>>> print a
[ 1. 0. 2. -10.]
>>> b = a.astype(n.integer)
>>> b.dtype
dtype('int32')
>>> print b
[ 1 0 2 -10]
dmitrey wrote:
> hi all,
> 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])
>
> Thx in advance, D.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
--
Christopher Hanley
Systems Software Engineer
Space Telescope Science Institute
3700 San Martin Drive
Baltimore MD, 21218
(410) 338-4338
More information about the NumPy-Discussion
mailing list