DEV Community

Cover image for Matrix multiplication in Python
Vidyasagar SC Machupalli
Vidyasagar SC Machupalli

Posted on • Edited on

1

Matrix multiplication in Python

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

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay