I have 4 different numpy arrays with 40 values in each and i want to add all the elements at position 0 of 4 arrays together and store in another array at loc 0. All the elements at location 1 and store in location 1 and same for all 40 elements of 4 arrays . How should I do in python?
Asked
Active
Viewed 59 times
-3
-
1it would be good if you can give an example of what you want, it seems to me you want to simply add 4 arrays – moth Dec 23 '21 at 08:27
-
1no minimum effor code example, poor explanation, no research done. – Dariusz Krynicki Dec 23 '21 at 08:28
-
Using numpy, it should be as simple as `a + b`... – Tomerikoo Dec 23 '21 at 09:18
-
Does this answer your question? [Numpy element-wise addition with multiple arrays](https://stackoverflow.com/questions/66111665/numpy-element-wise-addition-with-multiple-arrays) – Tomerikoo Dec 23 '21 at 09:19
1 Answers
0
I suggest to do some study on broadcasting
NumPy operations are usually done on pairs of arrays on an element-by-element basis. In the simplest case, the two arrays must have exactly the same shape,
From your question it seems you are in the simplest use case, like the following:
import numpy as np
arr = np.arange(4)
arr+arr*arr+arr
#array([ 0, 3, 8, 15])
multiple operations on array of the same shape

Glauco
- 1,385
- 2
- 10
- 20
-
-
The example do exactly this, apply different operation element-wise on 4 array – Glauco Dec 23 '21 at 13:23