आइंस्टीन के योग सम्मेलन के साथ अदिश गुणन करने के लिए, पायथन में numpy.einsum () विधि का उपयोग करें। पहला पैरामीटर सबस्क्रिप्ट है। यह सबस्क्रिप्ट लेबलों की अल्पविराम से अलग की गई सूची के लिए सबस्क्रिप्ट निर्दिष्ट करता है। दूसरा पैरामीटर ऑपरेंड है। ये ऑपरेशन के लिए सरणियाँ हैं।
आइंसम () विधि ऑपरेंड पर आइंस्टीन के योग सम्मेलन का मूल्यांकन करती है। आइंस्टीन के योग सम्मेलन का उपयोग करते हुए, कई सामान्य बहु-आयामी, रैखिक बीजगणितीय सरणी संचालन को एक साधारण फैशन में दर्शाया जा सकता है। निहित मोड में इन्सम इन मूल्यों की गणना करता है। स्पष्ट मोड में, einsum अन्य सरणी संचालनों की गणना करने के लिए और अधिक लचीलापन प्रदान करता है, जिन्हें शास्त्रीय आइंस्टीन योग संचालन नहीं माना जा सकता है, अक्षम करके, या संक्षेप में निर्दिष्ट सबस्क्रिप्ट लेबल को मजबूर करके।
कदम
सबसे पहले, आवश्यक पुस्तकालयों को आयात करें -
import numpy as np
numpy.arange() और reshape() -
. का उपयोग करके एक सरणी बनाएंarr = np.arange(6).reshape(2,3)
वैल अदिश है -
val = 2
सरणी प्रदर्शित करें -
print("Our Array...\n",arr)
आयामों की जाँच करें -
print("\nDimensions of our Array...\n",arr.ndim) डेटाटाइप प्राप्त करें -
print("\nDatatype of our Array object...\n",arr.dtype)
आकार प्राप्त करें -
print("\nShape of our Array object...\n",arr.shape) आइंस्टीन के योग सम्मेलन के साथ अदिश गुणन करने के लिए, numpy.einsum() विधि का उपयोग करें -
print("\nResult (scalar multiplication)...\n",np.einsum('..., ...', val, arr))
उदाहरण
import numpy as np
# Create an array using the numpy.arange() and reshape()
arr = np.arange(6).reshape(2,3)
# 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 perform scalar multiplication with Einstein summation convention, use the numpy.einsum() method in Python.
print("\nResult (scalar multiplication)...\n",np.einsum('..., ...', val, arr)) आउटपुट
Array... [[0 1 2] [3 4 5]] Datatype of Array... int64 Dimensions of Array... 2 Shape of Array... (2, 3) Result (scalar multiplication)... [[ 0 2 4] [ 6 8 10]]