টেনসর ডট প্রোডাক্ট: numpy.tensordot()
numpy.tensordot() ফাংশন দুটি টেনসরের নির্দিষ্ট অক্ষগুলোর সাথে ডট প্রোডাক্ট গণনা করে। axes প্যারামিটারে দুটি অ্যাক্সের তালিকা দিতে হয়: (a_axes, b_axes)।
উদাহরণ: অক্ষ ((0,1), (0,1)) দিয়ে ডাবল কন্ট্রাকশন
import numpy as np
arr1 = np.array(range(1, 9)).reshape(2, 2, 2) # shape (2,2,2)
arr2 = np.array(['p', 'q', 'r', 's'], dtype=object).reshape(2, 2) # shape (2,2)
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)
# axes = ((0,1), (0,1))
result = np.tensordot(arr1, arr2, axes=((0, 1), (0, 1)))
print("\nTensor Dot Product:\n", result)
আউটপুট
Array1...
[[[1 2] [3 4]] [[5 6] [7 8]]]
Array2...
[['p' 'q'] ['r' 's']]
Dimensions of Array1... 3
Dimensions of Array2... 2
Shape of Array1... (2, 2, 2)
Shape of Array2... (2, 2)
Tensor Dot Product...
['pqqqrrrrrsssssss' 'ppqqqqrrrrrrssssssss']