एक सरणी और एक अदिश का आंतरिक उत्पाद प्राप्त करने के लिए, पायथन में numpy.inner() विधि का उपयोग करें। 1-डी सरणियों के लिए वैक्टर का साधारण आंतरिक उत्पाद, उच्च आयामों में अंतिम अक्षों पर एक योग उत्पाद। पैरामीटर 1 और बी, दो वैक्टर हैं। अगर 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.]]