title: Bottleneck on indexing performance with NumPy arrays (or creation of tuples)
body: <p>Imagine we have the following function:</p>
  
  <pre><code>def return_slice(self, k):
      return (self.A[self.C[k]:self.C[k+1]], self.B[self.C[k]:self.C[k+1]])
  </code></pre>
  
  <p>which is part of a class with arrays A, B and C which hold a ton of integers (upwards of 10^5). While calling this function a few times is fast enough, I've been noticing that ~2 million calls to this function are taking a very long time (my last few experiences have been showing ~12 seconds). I've managed to do a bit better with this:</p>
  
  <pre><code>def return_slice(self, k):
      pos = slice(self.C[k], self.C[k + 1])
      return (self.A[pos], self.B[pos])
  </code></pre>
  
  <p>which brings that down to ~6 seconds. This is still a bit unacceptable to me... I feel like I should change the whole way my arrays are structured, but I'm bringing this question to you because there may be something that I'm missing on why this is so slow.</p>
  
  <p>Bear in mind that a "structure" to the values of k cannot be assumed, just assume that it is random for every execution.</p>
  
  <p>I also think the creation of the tuple before returning may be the problem here, but it will take a ton of work to remove that -- I'd prefer to explore other alternatives.</p>
  
  <p>Edit: A and B have the same size, but not the same data type.</p>