Unten ist mein Skript, das im Grunde eine Nullmatrix von 12x8 mit 0 gefüllt erstellt. Dann möchte ich es einzeln ausfüllen. Also sagen wir mal, Spalte 2 Zeile 0 muss 5 sein. Wie mache ich das? Das folgende Beispiel zeigt, wie ich es tat, und die falsche (für meine Bedürfnisse) Ausgabe:Zellzuordnung einer 2-dimensionalen Matrix in Python, ohne Nummer
list_MatrixRow = []
list_Matrix = [] #Not to be confused by what the book calls, optimal alignment score matrix
int_NumbOfColumns = 12
int_NumbOfRows = 8
for i in range (0, int_NumbOfColumns): # Puts Zeros across the first Row
list_AlignMatrixRow.append(0)
for i in range (0, int_NumbOfRows):
list_AlignMatrix.append(list_AlignMatrixRow)
#add the list in another list to make matrix of Zeros
#-------------------THE ACTUAL PROBLEMATIC PART; ABOVE IS FINE(It Works)------------
list_AlignMatrix[2][0] = 5
# This is what logically makes sense but here is the output
# which happens but I don't want (there should be all 0s and
# only one 5 on the cell [2][0]):
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Thx jeder! Ich hab es geschafft. Was ich tat, machte eine Liste der gleichen Liste, die alle auf die gleiche Liste verweisen. Danke auch für die richtige Schreibweise in Python. Ich bin neu (4 Wochen) in der Verwendung von Python. Danke allen! – StudentOfScience