|
From: Sasha <nd...@ma...> - 2006-02-21 14:59:07
|
On the second thought, the difference between around and astype is not surprising because around operates in terms of decimals. Rather than adding rint, I would suggest to make a special case decimals=3D0 use C rint. > On 2/21/06, Mads Ipsen <mp...@os...> wrote: > > I suggest that rint() is added as a ufunc or is there any concerns > > here that I am not aware of? > > You might want to use astype(int). On my system it is much faster than a= round: > > > python -m timeit -s "from numpy import array, around; x =3D array([1.5]= *1000)" "around(x)" > 10000 loops, best of 3: 176 usec per loop > > python -m timeit -s "from numpy import array, around; x =3D array([1.5]= *1000)" "x.astype(int)" > 100000 loops, best of 3: 3.2 usec per loop > > the difference is too big to be explained by the fact that around > allocates twice as much memory for the result. In fact the following > equivalent of rint is still very fast: > > > python -m timeit -s "from numpy import array, around; x =3D array([1.5]= *1000)" "x.astype(int).astype(float)" > 100000 loops, best of 3: 6.48 usec per loop > |