What is the deg2rad function in NumPy?

The deg2rad function is used to convert degrees to radians. It comes as part of NumPy, which is a library of the high-level coding language Python.

Syntax

numpy.deg2rad(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'deg2rad'>

A universal function (ufunc) is a function that operates on ndarrays in an element-by-element fashion. The deg2rad method is a universal function.

Parameters

The deg2rad function accepts the following arguments.

  • x: array-like structure on the contents of which the deg2rad function will be applied. The input array will be in radians.

  • out (optional): the function’s output is stored at this location.

  • where (optional): if set True, a universal function is calculated at this position.

  • casting (optional): enables the user to decide how the data will be cast. If set as same_kind, safe casting will take place.

  • order (optional): determines the memory layout of the output. For example, if set as K, the function reads data in the order they are written in memory.

  • dtype (optional): the data type of the array.

  • subok (optional): to pass subclasses, subokmust be set as True.

Return value

The deg2rad function returns the corresponding degree values of type float in an ndarray. If the optional out parameter is provided, it returns a reference.

If x is a scalar, the return value is also a scalar.

Example

The example below demonstrates how to apply the deg2rad function on an array that contains 4 degree values.

import numpy as np
degree=[180, 360, 720, 1440]
print(np.deg2rad(degree))

Free Resources

HowDev By Educative. Copyright ©2025 Educative, Inc. All rights reserved