使用 Python 中的 scimath 计算 10 为底的对数


若要使用 scimath 计算 10 为底的对数,请在 Python Numpy 中使用 scimath.log10() 方法。此方法返回 x 值(值)的以 10 为底的对数。如果 x 是标量,则 out 也为标量,否则返回数组对象。

对于在 real x < 0 时返回 NAN 的 log10(),请使用 numpy.log10(不过请注意,否则 numpy.log10 和此 log10 是相同的,即对于 x = 0 都返回 -inf,对于 x = inf 返回 inf,特别是当 x.imag != 0 时返回复主值)。第一个参数 x 是(是)要计算其(其)以 10 为底的对数的值(值)。

步骤

首先导入必需的库 -

import numpy as np

使用 array() 方法创建 numpy 数组 -

arr = np.array([10**1, -10**1, -10**2, 10**2, -10**3, 10**3])

显示数组 -

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 计算 10 为底的对数,请使用 scimath.log10() 方法 -

print("\nResult (log10)...\n",np.emath.log10(arr))

示例

Open Compiler
import numpy as np # Creating a numpy array using the array() method arr = np.array([10**1, -10**1, -10**2, 10**2, -10**3, 10**3]) # 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 compute the logarithm base 10 with scimath, use the scimath.log10() method in Python Numpy print("\nResult (log10)...\n",np.emath.log10(arr))

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

Our Array...
[ 10 -10 -100 100 -1000 1000]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(6,)

Result (log10)...
[1.+0.j 1.+1.36437635j 2.+1.36437635j 2.+0.j
3.+1.36437635j 3.+0.j ]

已更新日期: 2022 年 3 月 1 日

129 次浏览

开启你 事业

完成课程获取认证

入门
广告