在Python中用scimath计算反余弦
在这篇文章中,我们将使用NumPy在Python中用scimath计算反余弦。
numpy.arccos 方法
NumPy数组可以通过不同的方式创建,比如,通过各种数字,以及定义数组的大小。它也可以通过使用各种数据类型来创建,如列表、图元等。NumPy包中的np.emath.arccos()方法是用来在python中用scimath计算反余弦的。下面是arccos方法的语法。
语法: numpy.arccos(x, out=None, where=True)
参数:
- x: array_like
- out:ndarray(可选)的tuple。
返回: 返回实部位于[0, pi]内的角度z。
示例 1:
这里,我们将创建一个NumPy数组,并使用np.emath.arccos()来计算给定值的反余弦。数组的形状由.shape属性找到,数组的尺寸由.ndim属性找到,数组的数据类型是.type属性。
import numpy as np # Creating an array array = np.array([1,2,-3, -4]) print(array) # shape of the array is print("Shape of the array is : ",array.shape) # dimension of the array print("The dimension of the array is : ",array.ndim) # Datatype of the array print("Datatype of our Array is : ",array.dtype) # computing inverse cosine print(np.emath.arccos(array))
输出:
[ 1 2 -3 -4] Shape of the array is : (4,) The dimension of the array is : 1 Datatype of our Array is : int64 [0. -0.j 0. -1.3169579j 3.14159265-1.76274717j 3.14159265-2.06343707j]
示例 2:
在这个例子中,我们以复数为输入,寻找反余弦。
import numpy as np # Creating an array array = np.array([1-2j,2+4j,-3+1j, -4+5j]) print(array) # shape of the array is print("Shape of the array is : ",array.shape) # dimension of the array print("The dimension of the array is : ",array.ndim) # Datatype of the array print("Datatype of our Array is : ",array.dtype) # computing inverse cosine print(np.emath.arccos(array))
输出:
[ 1.-2.j 2.+4.j -3.+1.j -4.+5.j] Shape of the array is : (4,) The dimension of the array is : 1 Datatype of our Array is : complex128 [1.14371774+1.52857092j 1.11692612-2.19857303j 2.80389154-1.8241987j 2.2396129 -2.55132163j]
版权声明:本页面内容旨在传播知识,为用户自行发布,若有侵权等问题请及时与本网联系,我们将第一时间处理。E-mail:284563525@qq.com