Is there a way to do a reshape on numpy arrays but inplace. My problem is that my array is very big so any unnecessary copies strain the memory.
My current approach is like this:
train_x = train_x.reshape(n,32*32*3)
this doesn't exactly solve the problem since it creates a new array and then attributes the label train_x
to the new array.
In a normal case this would be ok, since the garbage collector would very soon collect the original array.
The problem is that I have something like this:
train_x, train_y = train_set
train_x = train_x.reshape(n,32*32*3)
So in this case even though the train_x
no longer points to the original array, there is still a pointer to the original array inside of train_set
.
I want a way that changes all pointers of the previous array to this new array. Is there a way?
Or maybe there is some other way of dealing with this?