0
# 3x3
X = [[0,0,0],
[0 ,5,6],
[7 ,0,0]]
# 3x4
Y = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
# 3x4
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
# iterate through rows of X
for i in range(len(X)):
# iterate through columns of Y
for j in range(len(Y[0])):
# iterate through rows of Y
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
#This code multiplies matrices X and Y and puts the resulting product into matrix result
#It then prints the matrix result row by row, so it looks like a matrix on the screen
for r in result:
print(r)
在这里,我有一个计划,将制定出一个矩阵,但我不知道如何运行程序时,而不是事先输入的数字矩阵程序要求用户输入
什么“用户输入蟒蛇”在搜索引擎回报? –
http://stackoverflow.com/questions/32466311/taking-nn-matrix-input-by-user-in-python –
一种自然的方法是让用户输入字符串,如'[[1,2],[ 3,4]]'然后解析这些字符串(这很简单)。 –