0

# Could you write a matrix-number multiplication program without numpy, I can talk to numpy

4 Answers

+ 4

Mulitiplication number with matrix:
l = [[1,2,3],
[4,5,6]]
n = 2
lists = []
end=[]
for i in l:
for m in i:
mul = m*n
lists.append(mul)
end.append(lists)
lists = []
print(end)
Multiplication matrix with matrix:
I dont have any idea to solve it🤣

+ 1

"I can talk to numpy"
What you want to say?

0

But with your attempt.

0

"""
Sting
they are many kind/ways to do matrix multiplication by another matrix:
1) M1×M2: common matrix multiplication
2) M1•M2: Hadamard multiplication
3) M1⊗M2: Kronecker multiplication
bellow the code for the common one (used in computer 3d graphics to multiply list of homogeneous 4d vectors by 4x4 square transform matrices and/or combine 4x4 square transform matrices)...
"""
def common_mat_mult(m1,m2):
com = len(m2)
if len(m1[0]) != com:
return # imcompatible matrix
row? col = len(m1), len(m2[0])
m = list2d(row,col)
for r in range(row):
for c in range(col):
for i in range(com):
m[r][c] += m1[r][i] * m2[i][c]
return m
def list2d(row,col,init=0):
return [[init for c in range(col)] for r in range(row)]