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

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

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

要使用log10()在实数x<0时返回NAN,请使用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))

示例

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))

输出

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 ]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程