Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
numpy
radians
degrees

What is the rad2deg function in NumPy?

Rukhshan Haroon

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

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

Syntax

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

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

Parameters

The rad2deg function accepts the following arguments.

  • x: array-like structure on the contents of which the rad2deg 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 rad2deg 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 rad2deg function on an array that contains 4 radian values.

import numpy as np
rad=[np.pi, np.pi * 2, np.pi * 4, np.pi * 8]
print(np.rad2deg(rad))

RELATED TAGS

python
numpy
radians
degrees

CONTRIBUTOR

Rukhshan Haroon
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring