lundi 13 février 2017

Python: Replace Value in Only One Row

Vote count: 0

I have a list of two rows, and am just trying to replace one variable in one row, but it's changing the variable in both rows. Below is the code:

rowOfZeros_4cols = []

for i in range(0,4):
    rowOfZeros_4cols.append(0.)

twoRows = [rowOfZeros_4cols, rowOfZeros_4cols]

mat_Zeros = twoRows

mat_Zeros[0][2] = 1.

The output looks like:

[[0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 1.0, 0.0]] 

When I want it to look like:

[[0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 0.0]] 

What am I doing wrong? This seems like it should be pretty straight forward.

Thanks in advance, Eric

asked 43 secs ago

Let's block ads! (Why?)



Python: Replace Value in Only One Row

Aucun commentaire:

Enregistrer un commentaire