Để lấy sản phẩm Bên trong của hai mảng, hãy sử dụng phương thức numpy.inner () trong Python. Tích bên trong thông thường của vectơ đối với mảng 1-D, ở các kích thước cao hơn là tích tổng trên các trục cuối cùng. Các tham số là 1 và b, hai vectơ. Nếu a và b không theo phương pháp nào thì kích thước cuối cùng của chúng phải khớp nhau.
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ảng một chiều hai chiều bằng cách sử dụng phương thức array () -
arr1 = np.array([5, 10, 15]) arr2 = np.array([20, 25, 30])
Hiển thị các mảng -
print("Array1...\n",arr1)
print("\nArray2...\n",arr2) Kiểm tra Kích thước của cả hai mảng -
print("\nDimensions of Array1...\n",arr1.ndim)
print("\nDimensions of Array2...\n",arr2.ndim) Kiểm tra Hình dạng của cả hai mảng -
print("\nShape of Array1...\n",arr1.shape)
print("\nShape of Array2...\n",arr2.shape) Để lấy sản phẩm bên trong của hai mảng, hãy sử dụng phương thức numpy.inner () trong Python -
print("\nResult (Inner Product)...\n",np.inner(arr1, arr2)) Ví dụ
import numpy as np
# Creating two numpy One-Dimensional array using the array() method
arr1 = np.array([5, 10, 15])
arr2 = np.array([20, 25, 30])
# Display the arrays
print("Array1...\n",arr1)
print("\nArray2...\n",arr2)
# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",arr1.ndim)
print("\nDimensions of Array2...\n",arr2.ndim)
# Check the Shape of both the arrays
print("\nShape of Array1...\n",arr1.shape)
print("\nShape of Array2...\n",arr2.shape)
# To get the Inner product of two arrays, use the numpy.inner() method in Python
# Ordinary inner product of vectors for 1-D arrays, in higher dimensions a sum product over the last axes.
print("\nResult (Inner Product)...\n",np.inner(arr1, arr2)) Đầu ra
Array1... [ 5 10 15] Array2... [20 25 30] Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (3,) Shape of Array2... (3,) Result (Inner Product)... 800