Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding values in a numpy array resulting from matrix calculation

I have some calculation involving two matrices both represented in numpy arrays.

After the calculation, i obtain a vector of floats represented in another numpy array.

I want to round up/down the values in this resultant vector, e.g. if the calculation gives:

array([1.33333, 2.56, 9.99999, 16.0])

then it should be rounded to:

array([1, 3, 10, 16])

What is the fastest way to do this?

like image 869
MLister Avatar asked Jan 16 '23 03:01

MLister


1 Answers

NumPy arrays have a round method:

In [73]: x = np.array([1.33333, 2.56, 9.99999, 16.0])

In [74]: x.round()
Out[76]: array([  1.,   3.,  10.,  16.])
like image 53
unutbu Avatar answered Jan 18 '23 22:01

unutbu