📜  Python numpy.tan()(1)

📅  最后修改于: 2023-12-03 15:04:06.791000             🧑  作者: Mango

Python numpy.tan()

The numpy.tan() function is used to compute the tangent of an input array or scalar angle in radians. It is part of the NumPy library, which is a fundamental package for scientific computing in Python.

Syntax
numpy.tan(x, out=None)
Parameters
  • x: The input angle in radians, which can be an array or a scalar.
  • out (optional): An alternative output array in which to place the result. It must have the same shape as the input.

The numpy.tan() function returns an array with elements representing the tangent of each corresponding element in the input array.

Usage

To use numpy.tan(), you need to import the NumPy library:

import numpy as np

Example 1: Compute tangent of a scalar angle

angle = np.pi/3
result = np.tan(angle)
print(result)

Output:

1.7320508075688767

Example 2: Compute tangent of an array of angles

angles = np.array([0, np.pi/4, np.pi/2])
result = np.tan(angles)
print(result)

Output:

[ 0.00000000e+00  1.00000000e+00  1.63312394e+16]
Additional information
  • By default, the numpy.tan() function returns an array with dtype float64. To specify a different dtype, use the dtype argument.
  • The input angles are considered to be in radians and not in degrees. To convert from degrees to radians, you can use the numpy.radians() function.

For more information and options, refer to the official NumPy documentation.

Remember to consult the NumPy documentation and experiment with the function to explore its full capabilities.