ในการรับผลิตภัณฑ์ Inner ของอาร์เรย์หลายมิติสองอาร์เรย์ ให้ใช้เมธอด numpy.inner() ใน Python ผลคูณภายในทั่วไปของเวกเตอร์สำหรับอาร์เรย์ 1-D ในมิติที่สูงกว่า เป็นผลคูณรวมของแกนสุดท้าย พารามิเตอร์คือ 1 และ b เวกเตอร์สองตัว หาก a และ b ไม่ใช่สเกลาร์ มิติข้อมูลสุดท้ายจะต้องตรงกัน
ขั้นตอน
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import numpy as np
การสร้างอาร์เรย์สองมิติ numpy โดยใช้เมธอด array() -
arr1 = np.array([[5, 10], [15, 20]]) arr2 = np.array([[6, 12], [18, 24]])
แสดงอาร์เรย์ -
print("Array1...\n",arr1)
print("\nArray2...\n",arr2) ตรวจสอบขนาดของอาร์เรย์ทั้งสอง -
print("\nDimensions of Array1...\n",arr1.ndim)
print("\nDimensions of Array2...\n",arr2.ndim) ตรวจสอบรูปร่างของอาร์เรย์ทั้งสอง -
print("\nShape of Array1...\n",arr1.shape)
print("\nShape of Array2...\n",arr2.shape) ในการรับผลิตภัณฑ์ Inner ของอาร์เรย์หลายมิติสองอาร์เรย์ ให้ใช้เมธอด numpy.inner() ใน Python ผลคูณภายในทั่วไปของเวกเตอร์สำหรับอาร์เรย์ 1-D ในมิติที่สูงกว่า ผลิตภัณฑ์ผลรวมของแกนสุดท้าย -
print("\nResult (Inner Product)...\n",np.inner(arr1, arr2)) ตัวอย่าง
import numpy as np
# Creating two numpy Two-Dimensional array using the array() method
arr1 = np.array([[5, 10], [15, 20]])
arr2 = np.array([[6, 12], [18, 24]])
# 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 multi-dimensional arrays, use the numpy.inner() method in Python
print("\nResult (Inner Product)...\n",np.inner(arr1, arr2)) ผลลัพธ์
Array1... [[ 5 10] [15 20]] Array2... [[ 6 12] [18 24]] Dimensions of Array1... 2 Dimensions of Array2... 2 Shape of Array1... (2, 2) Shape of Array2... (2, 2) Result (Inner Product)... [[150 330] [330 750]]