I have a bit of strange problem with Python’s matrix making capabilities.
I have the following lists:
Test01 = [11,25,53,19]
Test02 = [2,6,4,8]
I want to write a code that adds each element in each list like so:
11 + 2, 11 + 6, 11 + 4, 11+ 8
25 + 2, 25 + 6
Etc. etc.
The following code I wrote
for i in test01:
c = [i+x for x in test02]
print(c)
This is the result I get out of it (and what I wanted).
[13,17,15,19]
[27,31,29,33]
[55,59,57,61]
[21,25,23,27]
Now I have a large dataset and made some calculations. The first two rows I selected to make the same calculation (i.e. the same type of matrix). However, Python only adds like so:
New_list01 = 1, 2, 3, 4
New_list02 = a,b,c,d
[[1+a, 2+ b, 3+ c, 4+ d]]
Only one row instead of the expected four Why is this? I converted the lists into numpy (.to_numpy) and to to list (.tolist()) as well. Still the same (wrong) answer. How can I still make the calculation I want?
Thanks for the help! (BTW, if there is a built-in function that can perform the task I am looking for then that would be even better.)