使用Python中的scimath計算自然對數
要使用scimath計算自然對數,請在Python Numpy中使用np.emath.log()方法。該方法返回x值的對數。如果x是標量,則out也是標量,否則會返回一個數組。第一個引數x是要計算其對數的值。
步驟
首先,匯入所需的庫−
import numpy as np
使用array()方法建立numpy陣列−
arr = np.array([np.inf, -np.inf, np.exp(1), -np.exp(1)])
顯示陣列−
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 Numpy中使用np.emath.log()方法−
print("\nResult (log)...\n",np.emath.log(arr))示例
import numpy as np
# Creating a numpy array using the array() method
arr = np.array([np.inf, -np.inf, np.exp(1), -np.exp(1)])
# 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 natural logarithm with scimath, use the np.emath.log() method in Python Numpy.
print("\nResult (log)...\n",np.emath.log(arr))輸出
Our Array... [ inf -inf 2.71828183 -2.71828183] Dimensions of our Array... 1 Datatype of our Array object... float64 Shape of our Array object... (4,) Result (log)... [inf+0.j inf+3.14159265j 1.+0.j 1.+3.14159265j]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP