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.]
dtype
We will use dtype=float
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]
where
Value to convert to radian or not we can decide by using another array filled with True and False.
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]
out
We can store the output in an array. We used shape() to create array (ar_out) of same shape() of our main array ar_rad.
We used ones() to create array of same shape() of our input array with degree values.
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)