I have an array of arrays:
parameters = [np.array([ 2.1e-04, -8.3e-03, 9.8e-01]), np.array([ 5.5e-04, 1.2e-01, 9.9e-01]), ...]
whose length is:
print len(parameters)
100
If we label the elements of parameters as parameters[i][j]:
it is then possible to access each number, i.e. print parameters[1][2] gives 0.99
I also have an array:
temperatures = [110.51, 1618.079, ...]
whose length is also 100:
print len(temperatures)
100
Let the elements of temperatures be k:
I would like to insert each kth element of temperatures into each ith element of parameters, in order to obtain final:
final = [np.array([ 2.1e-04, -8.3e-03, 9.8e-01, 110.51]), np.array([ 5.5e-04, 1.2e-01, 9.9e-01, 1618.079]), ...]
I have tried to make something like a zip loop:
for i,j in zip(parameters, valid_temperatures):
final = parameters[2][i].append(valid_temperatures[j])
but this does not work. I would appreciate if you could help me.
EDIT: Based on @hpaulj answer:
If you run Solution 1:
parameters = [np.array([ 2.1e-04, -8.3e-03, 9.8e-01]), np.array([ 5.5e-04, 1.2e-01, 9.9e-01])]
temperatures = [110.51, 1618.079]
for i,(arr,t) in enumerate(zip(parameters,temperatures)):
parameters[i] = np.append(arr,t)
print parameters
It gives:
[array([ 2.10000000e-04, -8.30000000e-03, 9.80000000e-01,
1.10510000e+02]), array([ 5.50000000e-04, 1.20000000e-01, 9.90000000e-01,
1.61807900e+03])]
which is the desired output.
In addition, Solution 2:
parameters = [np.array([ 2.1e-04, -8.3e-03, 9.8e-01]), np.array([ 5.5e-04, 1.2e-01, 9.9e-01])]
temperatures = [110.51, 1618.079]
parameters = [np.append(arr,t) for arr, t in zip(parameters,temperatures)]
print parameters
also gives the desired output.
As opposed to Solution 1, Solution 2 doesn't use the ith enumerate index. Therefore, if I just split Solution 2's [np.append ... for arr ] syntax the following way:
parameters = [np.array([ 2.1e-04, -8.3e-03, 9.8e-01]), np.array([ 5.5e-04, 1.2e-01, 9.9e-01])]
temperatures = [110.51, 1618.079]
for arr, t in zip(parameters,temperatures):
parameters = np.append(arr,t)
print parameters
The output contains only the last iteration, and not in an "array-format":
[ 5.50000000e-04 1.20000000e-01 9.90000000e-01 1.61807900e+03]
How would it be possible to make this to work, by printing all the iterations ? Thanks
parameters[i] = parameters[i].append(temperatures[i]). this should appendith element oftemperaturestoith element inparameterslist != np.array