একটি অ্যারে এবং একটি স্কেলারের অভ্যন্তরীণ পণ্য পেতে, পাইথনে numpy.inner() পদ্ধতিটি ব্যবহার করুন। 1-D অ্যারেগুলির জন্য ভেক্টরের সাধারণ অভ্যন্তরীণ গুণফল, উচ্চতর মাত্রায় শেষ অক্ষগুলির উপর একটি যোগফল। প্যারামিটার হল 1 এবং b, দুটি ভেক্টর। যদি a এবং b ননস্কেলার হয় তবে তাদের শেষ মাত্রা অবশ্যই মিলবে।
পদক্ষেপ
প্রথমে, প্রয়োজনীয় লাইব্রেরি আমদানি করুন-
import numpy as np
numpy.eye() ব্যবহার করে একটি অ্যারে তৈরি করুন। এই পদ্ধতিটি একটি 2-ডি অ্যারে প্রদান করে যার সাথে তির্যক এবং অন্য কোথাও শূন্য থাকে −
arr = np.eye(5)
ভ্যাল হল স্কেলার −
val = 2
ডেটাটাইপ চেক করুন −
print("\nDatatype of Array...\n",arr.dtype)
মাত্রা পরীক্ষা করুন −
print("\nDimensions of Array...\n",arr.ndim) আকৃতি পরীক্ষা করুন −
print("\nShape of Array...\n",arr.shape) একটি অ্যারে এবং একটি স্কেলারের বাইরের পণ্য পেতে, পাইথনে numpy.outer() পদ্ধতিটি ব্যবহার করুন -
print("\nResult (Outer Product)...\n",np.outer(arr, val)) একটি অ্যারে এবং একটি স্কেলারের অভ্যন্তরীণ পণ্য পেতে, পাইথনে numpy.inner() পদ্ধতিটি ব্যবহার করুন -
print("\nResult (Inner Product)...\n",np.inner(arr, val))
উদাহরণ
import numpy as np
# Create an array using numpy.eye(). This method returns a 2-D array with ones on the diagonal and zeros elsewhere.
arr = np.eye(5)
# The val is the scalar
val = 2
# Display the array
print("Array...\n",arr)
# Check the datatype
print("\nDatatype of Array...\n",arr.dtype)
# Check the Dimension
print("\nDimensions of Array...\n",arr.ndim)
# Check the Shape
print("\nShape of Array...\n",arr.shape)
# To get the Inner product of an array and a scalar, use the numpy.inner() method in Python
print("\nResult (Inner Product)...\n",np.inner(arr, val)) আউটপুট
Array... [[1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.] [0. 0. 0. 1. 0.] [0. 0. 0. 0. 1.]] Datatype of Array... float64 Dimensions of Array... 2 Shape of Array... (5, 5) Result (Inner Product)... [[2. 0. 0. 0. 0.] [0. 2. 0. 0. 0.] [0. 0. 2. 0. 0.] [0. 0. 0. 2. 0.] [0. 0. 0. 0. 2.]]