Để tính logarit tự nhiên với scimath, hãy sử dụng phương thức np.emath.log () trong Python Numpy. Phương thức này trả về nhật ký của (các) giá trị x. Nếu x là một đại lượng vô hướng, thì sẽ bị out, nếu không thì một mảng sẽ được trả về. Tham số đầu tiên, x là (các) giá trị mà nhật ký là (được) bắt buộc.
Các bước
Đầu tiên, hãy nhập các thư viện được yêu cầu -
import numpy as np
Tạo một mảng numpy bằng phương thức array () -
arr = np.array([np.inf, -np.inf, np.exp(1), -np.exp(1)])
Hiển thị mảng -
print("Our Array...\n",arr) Kiểm tra các thứ nguyên -
print("\nDimensions of our Array...\n",arr.ndim)
Lấy Datatype -
print("\nDatatype of our Array object...\n",arr.dtype) Lấy hình dạng -
print("\nShape of our Array object...\n",arr.shape)
Để tính logarit tự nhiên với scimath, hãy sử dụng phương thức np.emath.log () trong Python Numpy -
print("\nResult (log)...\n",np.emath.log(arr)) Ví dụ
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)) Đầu ra
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]