Để 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. Sản phẩm bên trong thông thường của vectơ cho mảng 1-D, ở các kích thước cao hơn một tích tổng trên các trục cuối cùng. Tham số là 1 và b, hai vectơ. Nếu a và b không phải là phân số, 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 hai mảng một chiều vô cùng phức tạp bằng cách sử dụng phương thức array () -
arr1 = np.arange(2).reshape((1,1,2)) arr2 = np.arange(6).reshape((3,2))
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 () -
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.arange(2).reshape((1,1,2))
arr2 = np.arange(6).reshape((3,2))
# 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... [[[0 1]]] Array2... [[0 1] [2 3] [4 5]] Dimensions of Array1... 3 Dimensions of Array2... 2 Shape of Array1... (1, 1, 2) Shape of Array2... (3, 2) Result (Inner Product)... [[[1 3 5]]]