NumPy | degrees method
degrees(~) method converts radians to degrees.
Note that this method is equivalent to Numpy's
The input array of degrees that you want to convert to radians.
Numpy array |
Instead of creating a new array, you can place the computed result into the array specified by
Values that are flagged as False will be ignored, that is, their original value will be uninitialized. If you specified the out parameter, the behavior is slightly different - the original value will be kept intact. Since this is a source of confusion for many, check examples below.
a is a scalar, then a scalar is returned. Otherwise, a Numpy array of floats is returned.
np.degrees([np.pi, 2 * np.pi])array([180., 360.])
Specifying an output array
a = np.zeros(2)np.degrees([np.pi, 2 * np.pi], out=a)aarray([180., 360.])
Specifying a boolean mask
np.degrees([np.pi, 2*np.pi, 3*np.pi], where=[False, True, False])array([ -0.98803162, 360. , -0.80115264])
Here, only the second number was used for calculation since it has a corresponding boolean of
True in the mask. You should notice how the values with
False yielded strange results - in fact, you should disregard them because they are uninitialized numbers that are of no practical use.
Now, if you specified the
out parameter, instead of uninitalized values, the original values will be left intact:
a = np.zeros(3)np.degrees([np.pi, 2*np.pi, 3*np.pi], out=a, where=[False, True, False])aarray([ 0., 360., 0.])