SP_
SP_

Reputation: 391

Two dimensional matrix as List of lists

I am beginner in python. I have a 3*3 matrix .I want to perform certain operations in that matrix, like matrix multiplication addition etc. I have represented my matrix as a list of lists as given below:

mat =[[23,45],[45,67],[24,56]]

Is there any inbuilt function for list to perform matrix multiplication, or do I need to write a separate function for it? Is there any better way to multiply two matrix?

Upvotes: 0

Views: 81

Answers (1)

gdlmx
gdlmx

Reputation: 6789

There is no build-in functions for matrix operation, that's why packages like numpy exist.

import numpy as np
mat = np.array([[23,45],[45,67],[24,56]])
np.dot(mat, mat.T)
# array([[2554, 4050, 3072],
#       [4050, 6514, 4832],
#       [3072, 4832, 3712]])

Upvotes: 1

Related Questions