我正在使用python。這個任務很簡單,我理解這個概念,我對計算機編程毫無知識,所以請溫和一些,並且儘量詳細地解釋一切,就好像我什麼都不知道,我正在努力學習。這表明用所有組合ijk,ikj,jik,jki,kij和kji返回相同的結果。下一步是用4000做同樣的事情(試着想象如何把4000放在矩陣中,拍攝自己。) 我知道有些東西像numpy,但我不知道如何使用它,但是我打算嘗試從基礎開始,直接從Windows終端。我想感謝你的時間,並幫助這裏的傢伙!謝謝!在這裏輸入嵌套循環全部
enter code here
X = [[1,2,3,4,5],
[6,7,8,9,10]]
Y = [[1,2],
[3,4],
[5,6],
[7,8],
[9,10]]
result = [[0,0],
[0,0]]
empty = [[0,0],
[0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
print""
for i in range(len(X)):
for k in range(len(Y)):
for j in range(len(Y[0])):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
del r[:]
print""
for i in range(len(X)):
for k in range(len(Y)):
for j in range(len(Y[0])):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
del range[:]
print""
for j in range(len(Y[0])):
for i in range(len(X)):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
for j in range(len(Y[0])):
for k in range(len(Y)):
for i in range(len(X)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
for k in range(len(Y)):
for i in range(len(X)):
for j in range(len(Y[0])):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
for k in range(len(Y)):
for j in range(len(Y[0])):
for i in range(len(X)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print r
result = empty
del r[:]
問題代碼,是該指數,爲第3集運行代碼的時候,沒有與該指數的一個問題,我不明白這一點。
result[i][j] += X[i][k] * Y[k][j]
IndexError: list index out of range
歡迎來到Stackoverflow!一般來說,當你發佈一個問題時,你想要堅持一個MCVE示例(http://stackoverflow.com/help/mcve),以便我們不必通讀如此長的代碼塊。這對於你收到的答案的時間表和質量肯定有幫助 –
當你使用'row','col'等等而不是'i','j'等名字時更容易 – furas
print'i','' j','k'和'result [i] [j]','X [i] [k]','Y [k] [j]'來查看哪個元素產生問題。 – furas