numpy
  1. numpy-deg2rad

NumPy: numpy.deg2rad

Introduction

This page explores the usage of the numpy.deg2rad function in NumPy, which is used for converting angles from degrees to radians.

numpy.deg2rad Function

Syntax

The syntax for the numpy.deg2rad function is as follows:

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

Example

Consider the following example:

import numpy as np

# Creating an array of angles in degrees
angles_deg = np.array([0, 45, 90, 180, 360])

# Converting angles to radians using numpy.deg2rad
angles_rad = np.deg2rad(angles_deg)

Output

After executing the above code, angles_rad will contain the corresponding angles in radians.

Explanation

The numpy.deg2rad function converts angles from degrees to radians. It takes an array of angles in degrees as input and returns an array with the same shape, where each element is the corresponding angle in radians.

Use

  • Trigonometric Calculations: Use numpy.deg2rad when working with trigonometric functions in NumPy, which typically use angles in radians.
  • Mathematical Transformations: Convert angles from degrees to radians for mathematical operations and transformations.

Important Points

  • The input array should contain angles in degrees.
  • The result is an array of the same shape as the input array, with angles converted to radians.

Summary

The numpy.deg2rad function is a convenient tool for converting angles from degrees to radians, providing a straightforward way to work with trigonometric functions and perform mathematical transformations. Whether you're dealing with geometric calculations or scientific computations, incorporating numpy.deg2rad into your NumPy workflows facilitates the seamless conversion of angle units.

Published on: