Say I want to use a np array as a fixed read-only queue and pop off the front of it. This is a natural way to do it:
def pop(k,q):
return q[:k],q[k:]
## example usage:
x = np.arange(1000)
for i in range(5):
a,x = pop(i,x)
print(a)
This seems to be fine, but I want to be sure that there's no hidden state or hidden references that build up if q=q[k:] gets executed thousands or millions of times. There doesn't seem to be: to take a slice, np simply stores a pointer to the original data buffer, and the new index. But I want to be sure, because if there is something I'm missing, I could represent this as a tuple (np.array,index), which is not as clean:
def pop0(k,q):
x,i = q
return x[i:i+k],(x,i+k)