I'm working with a lot of arrays, and I'd like to know if there's a way to use aliasing so that operations using a subset of the array do not need to "reslice" the array each time the global array is updated.
For example:
values = np.array([100, 200, 300, 400, 500, 600, 700, 800, 900, 1000])
index = np.array([2, 4, 8, 9])
sub_val = values[index]
This returns the following for sub_val:
sub_val = [300 500 900 1000]
If I change the original array:
values += 1
sub_val still returns:
sub_val = [300 500 900 1000]
instead of the desired:
sub_val = [301 501 901 1001]
Based on this, I'm assuming that all index/slice operations are creating a shallow copy. Is there a way to instead have sub_val be an alias of that subset of the array?
The goal is to be able to do this as efficiently as possible (The subset matrices are used for thousands of iterations).