Could you write a matrix-number multiplication program without numpy, I can talk to numpy | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

31st May 2021, 5:25 PM
Sting
Sting - avatar
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🤣
31st May 2021, 5:52 PM
aspad🇮🇷
aspad🇮🇷 - avatar
+ 1
"I can talk to numpy" What you want to say?
31st May 2021, 5:35 PM
Atul [Inactive]
0
But with your attempt.
31st May 2021, 5:31 PM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
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)]
31st May 2021, 10:52 PM
visph
visph - avatar