使用Python中的scimath计算反余弦

使用Python中的scimath计算反余弦

要使用scimath计算反余弦,在Python中使用numpy.emath.arccos()方法。 返回x的“主值”的反余弦。对于实数x,使得abs(x) <= 1,这是一个在闭区间[0, π]中的实数。 否则,返回复数的主值。

该方法返回x值的反余弦(s)。如果x是标量,则返回值也是标量,否则返回一个数组对象。第一个参数是需要计算反余弦的值。

步骤

首先,导入所需的库-

import numpy as np

使用array()方法创建一个numpy数组−

arr = np.array([1, -1, 2, 0])

显示数组 –

print("Array...\n", arr)

获取数组的类型 –

print("\nOur Array type...\n", arr.dtype)

获取数组的尺寸 –

print("\nOur Array Dimension...\n",arr.ndim)

使用scimath计算反余弦,在Python中使用numpy.emath.arccos()方法−

print("\nResult...",np.emath.arccos(arr))

示例

import numpy as np

# Create a numpy array using the array() method
arr = np.array([1, -1, 2, 0])

# Display the array
print("Array...\n", arr)

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimensions...\n",arr.ndim)

# Get the number of elements in the Array
print("\nNumber of elements...\n", arr.size)

# To compute the inverse cosine with scimath, use the numpy.emath.arccos() method in Python
print("\nResult...",np.emath.arccos(arr))

输出

Array...
[ 1 -1 2 0]

Our Array type...
int64

Our Array Dimensions...
1

Number of elements...
4

Result... [0. -0.j 3.14159265-0.j 0. -1.3169579j
1.57079633-0.j ]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程