I have been desperately trying to figure out why an array concatenation leads to the array being multiplied by 2 on the first iteration...
This is my code:
def run(filename, max_iter = 1e6):
data, fm = data_extraction(filename)
large_output = None
iteration_count = 0
while iteration_count < max_iter:
iteration_count += 1
print iteration_count
results = calculations(data, (0.9,1.1))
if large_output == None:
large_output = results[:,1] #stores the energy array
print large_output
else:
large_output = np.c_[ large_output, results[:,1]]
#large_output = np.vstack([large_output, power_and_energy_var[:,1]])
print large_output
and this is the console output for the print statement and 3 iterations only:
1
[ 3.59891391e+01 5.75841568e+00 ]
2
[[ 7.22402719e+01 3.62511328e+01]
[ 1.16726670e+01 5.91425129e+00]]
3
[[ 7.22402719e+01 3.62511328e+01 3.70141435e+01]
[ 1.16726670e+01 5.91425129e+00 6.02176042e+00]]
As you can see 7.22402719e+01 is about twice 3.59891391e+01, yet it doesn't occur for the successive iterations...
I have no idea why this is happening. I have tried everything I could possibly think off:
1) check what exactly was being executed using print statements 2) reloaded the kernel to erase any lingering variables 3) used np.vstack instead of np.c_ (same error)
Any help would be much welcome !!
large_output = results[:,1]is taking a view of part ofresults. If the array it's taking a view of gets changed, the view will reflect those changes. The concatenation (while slow, and a bad idea) probably has nothing to do with your problem.large_outputorresults[:,1]empty at the first iteration? The output suggests the stacked array is 1D there and in succesives ones 2D.