在Python中获取反三角正切值
反正切是一个多值函数:对于每个x,都有无限多个z满足tan(z) = x。习惯上,返回实部位于[-π/2, π/2]范围内的角度z。反正切也称为atan或tan⁻¹。
对于实数值输入数据类型,反正切总是返回实数输出。对于不能表示为实数或无穷大的每个值,它会产生nan并设置无效浮点错误标志。对于复数值输入,反正切是一个复解析函数,它具有[1j, infj]和[-1j, -infj]作为分支切割,并且在前者上从左连续,在后者上从右连续。
要找到反三角正切,请在Python Numpy中使用numpy.arctan()方法。该方法返回tan的反函数,因此如果y = tan(x),则x = arctan(y)。第一个参数是类数组。第二个和第三个参数是可选的。第二个参数是ndarray,结果存储在其中的位置。如果提供,则其形状必须与输入广播到一起。如果没有提供或为None,则返回一个新分配的数组。第三个参数是条件在输入上广播。在条件为True的位置,out数组将设置为ufunc结果。在其他地方,out数组将保留其原始值。
步骤
首先,导入所需的库:
import numpy as np
获取反三角正切。求1的反三角正切:
print("\nResult...",np.arctan(1))求-1的反三角正切:
print("\nResult...",np.arctan(-1))求0的反三角正切:
print("\nResult...",np.arctan(0))
求0.3的反三角正切:
print("\nResult...",np.arctan(0.3))示例
import numpy as np
# To find the Trigonometric inverse tangent, use the numpy.arctan() method in Python Numpy
# The method returns the inverse of tan, so that if y = tan(x) then x = arctan(y).
# A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
print("Get the Trigonometric inverse tangent...")
# finding arctan for 1
print("\nResult...",np.arctan(1))
# finding arctan for -1
print("\nResult...",np.arctan(-1))
# finding arctan for 0
print("\nResult...",np.arctan(0))
# finding arctan for 0.3
print("\nResult...",np.arctan(0.3))输出
Get the Trigonometric inverse tangent... Result... 0.7853981633974483 Result... -0.7853981633974483 Result... 0.0 Result... 0.2914567944778671
广告
数据结构
网络
关系型数据库管理系统(RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP