a | Input array with degree |
out | Optional , ndarray to store result |
where | Optional , array with True to get values and False to leave the value |
import numpy as np
# input in radians
ar_rad=np.array([1.57079633, 2.0943951, 2.7925268,3.14159265])
ar_deg=np.rad2deg(ar_rad)
print(ar_deg) # output in degree
Output
[ 90.00000018 119.99999986 159.99999982 179.99999979]
In above output in degree we can use round() to roundup the values to nearest number. The last line we will change.
print(np.round(ar_deg))
Output
[ 90. 120. 160. 180.]
import numpy as np
ar_rad=np.array([2.0943951, 2.7925268, 3.14159265])
ar_deg=np.rad2deg(ar_rad,dtype=float)
print(ar_deg)
Output
[119.99999986 159.99999982 179.99999979]
import numpy as np
ar_rad=np.array([2.0943951, 2.7925268, 3.14159265])
ar_where=np.array([True,False,True])
ar_deg=np.rad2deg(ar_rad,where=ar_where)
print(ar_deg)
Output
[119.99999986 2.7925268 179.99999979]
import numpy as np
ar_rad=np.array([2.0943951, 2.7925268, 3.14159265])
ar_out=np.ones(ar_rad.shape)
ar_deg=np.rad2deg(ar_rad,out=ar_out)
print(ar_deg)
print(ar_out)
print(ar_rad is ar_out)
Output
[119.99999986 159.99999982 179.99999979]
[119.99999986 159.99999982 179.99999979]
False
Numpy
radians()
bincount()
arange()
linspace()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.