rounding all element of an array with more than 1d
I've posted also to scipy group but with no luck. At first I thought it was an easy task but... I've to round the numbers inside of a 2d array but nothing seems to work. the only message I've found in the archive is an old function custom made for doing that.. wouldn't be useful to have it also included something that do this task in numpy ? here's and example of the error using round Traceback (most recent call last): File "<pyshell#25>", line 1, in <module> round(vp) TypeError: only length-1 arrays can be converted to Python scalars Any feedback appreciated
Giorgio Luciano wrote:
I've posted also to scipy group but with no luck. At first I thought it was an easy task but... I've to round the numbers inside of a 2d array but nothing seems to work. the only message I've found in the archive is an old function custom made for doing that.. wouldn't be useful to have it also included something that do this task in numpy ? here's and example of the error using round
Traceback (most recent call last): File "<pyshell#25>", line 1, in <module> round(vp) TypeError: only length-1 arrays can be converted to Python scalars
Any feedback appreciated _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
a = random.rand(2,4) a array([[ 0.88084812, 0.03112202, 0.72374646, 0.76379529], [ 0.20978501, 0.2647247 , 0.12690806, 0.78367502]]) round_(a) array([[ 1., 0., 1., 1.], [ 0., 0., 0., 1.]])
HTH, Nils
participants (2)
-
Giorgio Luciano -
Nils Wagner