Để tính logarit cơ số 2 với scimath, hãy sử dụng phương thức np.emath.log2 () trong Python Numpy. Phương thức này trả về cơ số log 2 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à cơ sở nhật ký 2 là (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, 16, np.exp(1), -np.exp(1), -32])
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 cơ số 2 với scimath, hãy sử dụng phương thức np.emath.log2 () trong Python Numpy. Phương thức này trả về cơ số log 2 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 được trả về -
print("\nResult (log2)...\n",np.emath.log2(arr)) Ví dụ
import numpy as np
# Creating a numpy array using the array() method
arr = np.array([np.inf, -np.inf, 16, np.exp(1), -np.exp(1), -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 compute the logarithm base 2 with scimath, use the np.emath.log2() method in Python Numpy
# The method returns the log base 2 of the x value(s). If x was a scalar, so is out, otherwise an array is returned.
print("\nResult (log2)...\n",np.emath.log2(arr)) Đầu ra
Our Array... [ inf -inf 16. 2.71828183 -2.71828183 -32. ] Dimensions of our Array... 1 Datatype of our Array object... float64 Shape of our Array object... (6,) Result (log2)... [ inf+0.j inf+4.53236014j 4. +0.j 1.44269504+0.j 1.44269504+4.53236014j 5. +4.53236014j]