reivax85 at gmail.com
Wed Oct 18 18:51:18 CEST 2006
> Il 18 Oct 2006 04:17:29 -0700, Sssasss ha scritto:
> > hi evrybody!
> > I wan't to multiply two square matrixes, and i don't understand why it
> > doesn't work.
> Can I suggest a little bit less cumbersome algorithm?
> def multmat2(A,B):
> if len(A)!=len(B): return "error" # this check is not enough!
> n = range(len(A))
> C = 
> for i in n:
> C.append(*len(A)) # add a row to C
> for j in n:
> a = A[i] # get row i from A
> b = [row[j] for row in B] # get col j from B
> C[i][j] = sum([x*y for x,y in zip(a,b)])
> return C
This one is really nice, i didn't knew the zip function, thank you
More information about the Python-list