Matrix multiplication in Python
Vidyasagar SC Machupalli

Vidyasagar SC Machupalli @vidyasagarmsc

About: A little bit of everything in this journey called LIFE

Location:
Austin, TX
Joined:
Feb 22, 2019

Matrix multiplication in Python

Publish Date: Jan 17 '23
1 0

Learn how to do matrix multiplication in Python using @ operator.

@ operator is supported in Python version 3.5 and above. The operator works on ndarrays

# Matrix multiplication using @
import numpy as np
import random

# Generate a list
X = [[i for i in random.sample(range(0, 10), 3)] for i in range(3)]
Y = [[i for i in random.sample(range(0, 10), 3)] for i in range(3)]

# You can use numpy
X = np.array(X)
Y = np.array(Y)

Z = X @ Y
print(Z)

Enter fullscreen mode Exit fullscreen mode

@vidyasagar Machupalli

Comments 0 total

    Add comment