a | Input array with degree |
out | Optional , ndarray to store result |
import numpy as np
ar=np.array([1.57079, 2.0943, 2.792,3.1415])
print(np.round(ar))
Output
[2. 2. 3. 3.]
ar=np.array([1.57079, 2.0943, 2.792,3.1415])
print(np.round(ar,2))
Output
[1.57 2.09 2.79 3.14]
Or we can specify like this for three decimal places.
print(np.round(ar,decimals=3))
Output
[1.571 2.094 2.792 3.142]
import numpy as np
ar=np.array([1.57079, 2.0943, 2.792,3.1415])
ar_out=np.ones(ar.shape)
ar=np.round(ar,out=ar_out)
print(ar)
print(ar_out)
print(ar is ar_out) # True
Output
[2. 2. 3. 3.]
[2. 2. 3. 3.]
True
import numpy as np
ar=np.array([435, 478, 1020,1089,22348])
print(np.round(ar,decimals=-2))
Output
[ 400 500 1000 1100 22300]
import numpy as np
ar=np.array([435, 478, 1020,1889,22348])
print(np.round(ar,decimals=-3))
Output
[ 0 0 1000 2000 22000]
Numpy
rad2deg()
bincount()
arange()
linspace()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.