title: FIFO method using numpy
body: <p>I would like to implement the FIFO method using numpy. Specifically, I have a numpy array <code>STOCK</code> which looks like this</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy
  
  numpy.random.seed(1)
  STOCK = numpy.random.randint(1, 9, size=(10_000, 10)) 
  
  STOCK = array([
         [6, 4, 5, ..., 6, 8, 1],
         [1, 2, 5, ..., 2, 3, 5],
         [7, 6, 3, ..., 5, 6, 7],
         ...,
         [2, 5, 8, ..., 7, 6, 1],
         [2, 8, 7, ..., 2, 8, 4],
         [1, 2, 6, ..., 1, 1, 3]])
  </code></pre>
  
  <p>, where each row represents a different product category and each column the number of items bought at a specific date.</p>
  
  <p>Now, I have second array <code>SOLD</code> which looks like this</p>
  
  <pre class="lang-py prettyprint-override"><code>SOLD = numpy.random.randint(1, 9, size=10_000)
  SOLD = array([1, 7, 3, ..., 6, 8, 5])
  </code></pre>
  
  <p>where each number represents the number of products sold per category.</p>
  
  <p><strong>Now I want to update the <code>STOCK</code> array using the <a href="https://en.wikipedia.org/wiki/FIFO_and_LIFO_accounting" rel="nofollow noreferrer">FIFO</a> method.</strong> Meaning, I want to <em>book out</em> the first cumulative n elements per product category. In the above case the output should be something like</p>
  
  <pre class="lang-py prettyprint-override"><code>UPDATED_STOCK= array([
         [5, 4, 5, ..., 6, 8, 1],  # 6-1, 4, 5,     ... BOOKED OUT=1
         [0, 0, 1, ..., 2, 3, 5],  # 1-1, 2-2, 5-4, ... BOOKED OUT=7
         [4, 6, 3, ..., 5, 6, 7],  # 7-3, 6, 3,     ... BOOKED OUT=3
         ...,
         [0, 1, 8, ..., 7, 6, 1],  # 2-2, 5-4, 8,   ... BOOKED OUT=6
         [0, 2, 7, ..., 2, 8, 4],  # 2-2, 8-6, 7,   ... BOOKED OUT=8
         [0, 0, 4, ..., 1, 1, 3]]) # 1-1, 2-2, 6-2, ... BOOKED OUT=5
  </code></pre>
  
  <p>Yet, I am unsure how to solve this. Any ideas?</p>