-3

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?

4
  • 1
    it would be good if you can give an example of what you want, it seems to me you want to simply add 4 arrays Commented Dec 23, 2021 at 8:27
  • 1
    no minimum effor code example, poor explanation, no research done. Commented Dec 23, 2021 at 8:28
  • Using numpy, it should be as simple as a + b... Commented Dec 23, 2021 at 9:18
  • Does this answer your question? Numpy element-wise addition with multiple arrays Commented Dec 23, 2021 at 9:19

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

OP just wants to do element-wise addition between 4 arrays...
The example do exactly this, apply different operation element-wise on 4 array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.