title: Reduce Memory Usage when Running Numpy Array Operations
body: <p>I have a fairly large <code>NumPy</code> array that I need to perform an operation on but when I do so, my ~2GB array requires ~30GB of RAM in order to perform the operation. I've read that <code>NumPy</code> can be fairly clumsy with memory usage but this seems excessive. </p>
  
  <p>Does anyone know of an alternative way to apply these operations to limit the RAM load? Perhaps row-by-row/in place etc.?</p>
  
  <p>Code below (ignore the meaningless calculation, in my code the coefficients vary):</p>
  
  <pre><code>import xarray as xr 
  import numpy as np
  
  def optimise(data):
  
      data_scaled_offset = (((data - 1000) * (1 / 1)) + 1).round(0)
      return data_scaled_offset.astype(np.uint16)
  
  # This could also be float32 but I'm using uint16 here to reduce memory load for demo purposes
  ds = np.random.randint(0, 12000, size=(40000,30000), dtype=np.uint16)
  
  ds = optimise(ds) # Results in ~30GB RAM usage
  </code></pre>