使用 Python 中的 scimath 返回输入值幂的结果
要使用 scimath 返回输入值幂的结果,请在 Python 中使用 scimath.power() 方法。返回 x 的 p 次幂,即 x**p 的结果。如果 x 和 p 是标量,则 out 也是标量,否则返回数组。如果 x 包含负值,则输出将转换为复数域。参数 x 是输入值。
参数 p 是 x 提升到的幂。如果 x 包含多个值,则 p 必须是标量,或者包含与 x 相同数量的值。在后一种情况下,结果为 x[0]**p[0]、x[1]**p[1] 等。
步骤
首先,导入所需的库 -
import numpy as np
使用 array() 方法创建 NumPy 数组 -
arr = np.array([2, 4, 8, 16, 32])
显示数组 -
print("Our Array...\n",arr)检查维度 -
print("\nDimensions of our Array...\n",arr.ndim)
获取数据类型 -
print("\nDatatype of our Array object...\n",arr.dtype)获取形状 -
print("\nShape of our Array object...\n",arr.shape)要使用 scimath 返回输入值幂的结果,请在 Python 中使用 scimath.power() 方法 -
print("\nResult...\n",np.emath.power(arr, 2))示例
import numpy as np
# Creating a numpy array using the array() method
arr = np.array([2, 4, 8, 16, 32])
# Display the array
print("Our Array...\n",arr)
# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)
# Get the Shape
print("\nShape of our Array object...\n",arr.shape)
# To return the result of the power to which the input value is raised with scimath, use the scimath.power() method in Python
print("\nResult...\n",np.emath.power(arr, 2))输出
Our Array... [ 2 4 8 16 32] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (5,) Result... [ 4 16 64 256 1024]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP