I have a large 2d numpy array and I want to remove subsets of it and handle what remains to a function. I need to do this for many subsets, and thus I would ideally not want to create a copy of the array each time. The function doesn't change any values in the array.
mat = np.load(filename)
mat_1 = mat[:i,:]
mat_2 = mat[j:,:]
So far, mat_1 and mat_2 are views. Then I would like to do
mat_s = np.concatenate((mat_1,mat_2))
result = func(mat_s)
but without making a copy. Is this possible?
mat[j:i,:]?(100, 1)withi=50andj=20. The resultingnp.concatenatecreates an overlapping resulting array, whereas yourmat[j:i,:]does not.j > i, thennp.concatenatedoes not create an overlapping array, but concats two separated arrays. Still Kasramvd's solution won't work. filippo has shown a good way to deal with that.