Instagram
youtube
Facebook
Twitter

Element-wise Product with Transpose in NumPy

A Element-wise Product with Transpose in NumPy?
Code Explanation:
Library Import:
numpy is imported as np to handle arrays and mathematical operations.
Array Creation: A 2D NumPy array arr is created with shape (2, 2).
Transpose: arr.T computes the transpose of the array, flipping rows and columns.
Element-wise Product: arr * arr.T multiplies each element in the array with the corresponding element in the transpose (same positions).
Store Result: The result is stored in the variable product.

 

Program:

import numpy as np

arr = np.array([[1, 2], [3, 4]])

product = arr * arr.T

print(product)