ThisCalculator

Everyday

Numpy Convert Degrees to Radians

Updated · Standard formula, shown below

Radians 3.141593 rad
Degrees
180 °
You entered

Numpy Convert Degrees to Radians

To convert degrees to radians in NumPy, use numpy.radians() (or np.deg2rad(), which is an alias). Simply pass a number or an array of numbers to the function, and it returns the equivalent angle(s) in radians.

Formula

The conversion uses the standard mathematical relationship:

radians = degrees × (π / 180)

  • degrees – the angle in degrees (°)
  • radians – the equivalent angle in radians (rad)
  • π (pi) – approximately 3.141592653589793

This formula works because a full circle is 360° and also 2π radians. Dividing 2π by 360 gives π/180, the conversion factor for one degree.

Worked Example

Using the default value of 180 degrees:

  1. Write down the formula: radians = degrees × (π / 180)
  2. Plug in 180 for degrees: radians = 180 × (π / 180)
  3. Simplify: 180 / 180 = 1, so radians = π
  4. π ≈ 3.141592653589793

Thus, 180 degrees equals π radians, or approximately 3.141593 radians (rounded to 6 decimal places). This matches the calculator output above.

Why Convert Degrees to Radians in NumPy?

NumPy’s trigonometric functions (sin, cos, tan, etc.) expect angles in radians, not degrees. If you feed them degrees directly, you’ll get incorrect results. For instance, np.sin(90) returns about 0.894, which is the sine of 90 radians, not 90 degrees. Converting first gives the correct value: np.sin(np.radians(90)) returns 1.0.

This conversion is essential in scientific computing, engineering simulations, graphics programming, and any field that uses trigonometric calculations on data originally expressed in degrees.

How to Use numpy.radians()

The function is simple to call:

  • Single value: np.radians(45) returns approximately 0.785398.
  • Array: np.radians([0, 90, 180, 270, 360]) returns [0., 1.57079633, 3.14159265, 4.71238898, 6.28318531].
  • Multi-dimensional array: Works on any shape, element-wise.
  • In-place conversion: Use np.deg2rad(arr, out=arr) to modify the array directly, saving memory.

Both np.radians and np.deg2rad are identical; choose whichever reads better in your code.

Common Mistakes and Pitfalls

Beginners often mix up the two conversion functions. NumPy also provides np.rad2deg() (or np.degrees()) for the opposite direction. Using the wrong one will give a wildly different number.

Another common error is forgetting that the input can be an array. If you have a list of angles, you don’t need to loop; just pass the list directly. Also, be aware that the function does not modify the original array unless you use the out parameter – it returns a new array by default.

Rounding errors can accumulate if you convert back and forth repeatedly. In most applications, this is negligible, but for precision-critical work, consider keeping angles in radians throughout and only converting for display.

When to Use Each Function

Use np.radians() when you have angles in degrees and need radians for calculations. Use np.rad2deg() when you have radians and want degrees for readability or output. For example, after computing the angle of a vector with np.arctan2(), you might convert the result to degrees for a user interface.

If you are working with a constant like 180°, you can also just multiply by np.pi / 180 manually, but the built-in function is clearer and less error-prone.

Alternatives and Related Functions

NumPy also offers np.deg2rad() as an alias, and np.rad2deg()/np.degrees() for the reverse. For single numbers, Python’s built-in math.radians() and math.degrees() work similarly but don’t handle arrays.

If you’re working with data in degrees and need to compute trigonometric functions, you can also use the degree-based versions: np.sind(), np.cosd(), np.tand() (available in recent NumPy versions) which take degrees directly, avoiding conversion altogether.

Frequently Asked Questions

What is the difference between np.radians and np.deg2rad?

No difference – they are aliases of the same function. You can use either; it’s purely a matter of readability.

Can I convert a list of degrees to radians without a loop?

Yes, just pass the list to np.radians(). It will automatically convert it to a NumPy array and compute the radians element-wise.

Why does np.sin(90) give 0.894 instead of 1?

Because np.sin expects radians. 90 radians is not 90 degrees. Use np.sin(np.radians(90)) to get the correct sine of 90 degrees, which is 1.

How do I convert radians back to degrees?

Use np.rad2deg() or np.degrees(). For example, np.rad2deg(np.pi) returns 180.0.

Does np.radians work on multi-dimensional arrays?

Yes, it works element-wise on arrays of any shape, including matrices and higher-dimensional tensors.

Is there a performance difference between np.radians and multiplying by np.pi/180?

Negligible. The built-in function is implemented in C and is just as fast. Using the explicit multiplication might be marginally faster in some micro-benchmarks, but the difference is rarely meaningful.

Related

Formula used
in deg | Degrees | ° | 180 | 0
out rad | Radians | rad | deg * (pi / 180) | 6

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.