how to round an array in python

Solutions on MaxInterview for how to round an array in python by the best coders in the world

showing results for - "how to round an array in python"
Federica
13 Jan 2021
1import numpy as np
2x = np.round([1.45, 1.50, 1.55])
3print(x)
4x = np.round([0.28, .50, .64], decimals=1)
5print(x)
6x = np.round([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value
7print(x)
8
9#output
10#[ 1.  2.  2.]                                                          
11#[ 0.3  0.5  0.6]                                                       
12#[ 0.  2.  2.  4.  4.]