如何在python.3中将2D数组的行与另一个2D数组的列相乘而不是numpy?

时间:2013-05-03 17:02:06

标签: python python-3.x

NO_OF_ROWS_A=int(input("Enter the no. of rows in A: "))
NO_OF_COLUMNS_A=int(input("Enter the no. of columns in A: "))

NO_OF_ROWS_B=int(input("Enter the no. of rows in B : "))
NO_OF_COLUMNS_B=int(input("Enter the no. of columns in B: "))

mat_A=[[] for i in range(NO_OF_ROWS_A)]
for i in range(NO_OF_ROWS_A):
    for j in range (NO_OF_COLUMNS_A):
        print("Enter",i,j,"element for mat A: ")
        a=int(input())
        mat_A[i].append(a)

mat_B=[[] for i in range(NO_OF_ROWS_B)]
for i in range(NO_OF_ROWS_B):
    for j in range (NO_OF_COLUMNS_B):
        print("Enter",i,j,"element for mat B: ")
        b=int(input())
        mat_B[i].append(b)

mat_B_trans=list(itertools.zip_longest(*mat_B))
#can't understand the loop also
def list_a(mat_A, i):
    return [row[i] for column in mat_A]
def list_a(mat_B_trans, i):
    return [row[i] for column in mat_B_trans]
temp=[a*b for a,b in zip(list_a,list_b)]
mat_C=[[]for i in range(NO_OF_ROWS_A)]
for i in range(NO_OF_ROWS_A):
    for i in range(NO_OF_COLUMNS_B):
        c=int(input())
        mat_C[i].append(c)

0 个答案:

没有答案