title: How to mutate an array using a function in Numpy?
body: <p>I have a problem. The setup is more complex than what I show here, but that is to make the problem more understandable. Imagine I have the following script:</p>
  <pre><code>  import numpy as np
    import pandas as pd
  
    world_exports = np.zeros((4, 1))
  
    def sum_country_exports(nation, vector):
        vector = np.add(np.array(vector), np.array(exports[nation]))
  
    countries = ['United States', 'Canada', 'Mexico']
  
    list_X = [[10, 20, 40], [30, 40, 20], [40, 50, 60], [60, 70, 30]]
    exports = pd.DataFrame(list_X, columns = ['United States', 'Canada', 'Mexico']) 
  
    for country in countries:
        sum_country_exports(country, world_exports)
  </code></pre>
  <p>I have quarterly data on the exports of three countries (US, Canada, and Mexico). The idea is that the <code>world_exports</code> object is the sum of the exports of these countries for each quarter. It is crucial that this object is created outside the function.</p>
  <p>Then, I want to loop over the exports of each of these countries and add it to the <code>world_exports</code> array. Therefore, the expected result would be 10+20+40=70 for the first quarter (etc. for the other three quarters).</p>
  <p>Currently, <code>world_exports</code> goes back to zero each time the loop moves on to a new country.</p>
  <p>I already tried changing <code>vector = np.add...</code> to <code>vector[:] = ...</code> within the function. It changed the results, but they were very strange and not correct.</p>
  <p>Any help is greatly appreciated.</p>