-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?

user14924
  • 47
  • 2
  • 9

1 Answers1

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