Saturday, September 24, 2022

AI/ML How to round a numpy array?

 Numpy provides two identical methods to do this. Either use

np.round(data, 2)

or

np.around(data, 2)

as they are equivalent


>>> import numpy as np

>>> a = np.array([0.015, 0.235, 0.112])

>>> np.round(a, 2)

array([0.02, 0.24, 0.11])

>>> np.around(a, 2)

array([0.02, 0.24, 0.11])

>>> np.round(a, 1)

array([0. , 0.2, 0.1])


references:

https://stackoverflow.com/questions/46994426/how-to-round-a-numpy-array


No comments:

Post a Comment