I have the following code:
def TEST():
vals = [[0]*len(K_values)]*len(u_values)
for p in range(len(u_values)):
u = u_values[p]
for i in range(len(K_values)):
K = K_values[i]
vals[p][i] = u * K
return vals
u_values
and K_values
are 11-element long 1-D arrays. vals
is a 2-D array of zeros that (should have) has its [p][i]
element updated with u * K
upon every loop.
The problem is that instead of changing the index p upon each (outer) loop, python always uses p=0
- this means that upon every loop, only u_values[0]
is ever used. At first I thought this was because the outer for loop was only executing once; however, when viewing the code output (vals
), it is clear that the outer loop IS looping len(u_values)
times; it's just always with p=0
(otherwise, I would expect that only the zeroth column of the vals
array would be nonzero).