Rounding the elements of a Python array (numarray module)

Chris P. chris.peressotti at utoronto.ca
Fri Dec 3 18:31:12 EST 2004


Soooo I wasn't sure if no one replied because a) this question was too
dumb or b) this question was too hard... it was definitely the former.
 But I'll post the answer, anyway:

I forgot to keep in mind - when reading the documentation, assume that
a
>>> from numarray import *
occurred first.

So here's the way to do it:
>>> import numarray
>>> a = numarray.array([1.6, 1.9, 2.1])
>>> rounded_a = numarray.around(a)

and rounded_a then equals ([2., 2., 2.])

- Chris

chris.peressotti at utoronto.ca (Chris P.) wrote in message news:<3f233389.0411300857.7f522cd3 at posting.google.com>...
> Given an array called 'x' (created using the numarray library), is
> there a single command that rounds each of its elements to the nearest
> integer?



More information about the Python-list mailing list