[Numpy-discussion] int-ifying a float array
Robert Kern
robert.kern@gmail....
Mon Feb 22 21:58:23 CST 2010
On Mon, Feb 22, 2010 at 21:56, David Goldsmith <d.l.goldsmith@gmail.com> wrote:
> Hi! Is there a less cumbersome way (e.g., one that has a "cast-like" syntax
> and/or leverages broadcasting) than what follows to convert an array of
> floats to an array of ints? Here's what works:
>
>>>> import numpy as N
>>>> t = N.array([0.0, 1.0]); t.dtype
> dtype('float64')
>>>> t = N.array(t, dtype=int); t; t.dtype
> array([0, 1])
> dtype('int32')
t.astype(int)
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list