Re: [Numpy-discussion] int-ifying a float array

2010-02-22 Thread David Goldsmith
Thanks, both, I knew there had to be a better way. :-) DG On Mon, Feb 22, 2010 at 7:58 PM, Warren Weckesser < warren.weckes...@enthought.com> wrote: > Here's another way, using 'astype': > > In [1]: import numpy as np > > In [2]: x = np.array([1.0, 2.0, 3.0]) > > In [3]: y = x.astype(int) > > In

Re: [Numpy-discussion] int-ifying a float array

2010-02-22 Thread Warren Weckesser
Here's another way, using 'astype': In [1]: import numpy as np In [2]: x = np.array([1.0, 2.0, 3.0]) In [3]: y = x.astype(int) In [4]: y Out[4]: array([1, 2, 3]) Warren David Goldsmith wrote: > Hi! Is there a less cumbersome way (e.g., one that has a "cast-like" > syntax and/or leverages

Re: [Numpy-discussion] int-ifying a float array

2010-02-22 Thread Robert Kern
On Mon, Feb 22, 2010 at 21:56, David Goldsmith 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

[Numpy-discussion] int-ifying a float array

2010-02-22 Thread David Goldsmith
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=