1

I want to select a subset of elements from a large numpy array.

I'm near my memory limit so don't wish to create another array, rather I would like to do this downsampling in-place.

I've tried doing:

big_array = big_array[subset_of_big_array_indices]

But this results in an out of memory error.

Is there any way to do a selection (or deletion operation) in place?

RNs_Ghost
  • 1,687
  • 5
  • 25
  • 39
  • 1
    afaik NumPy doesn’t copy. What happens if you use a different name for the slice than for the original array? – mkrieger1 May 01 '19 at 15:10
  • @mkrieger1 another out of memory error – RNs_Ghost May 01 '19 at 15:11
  • 2
    Okay I was partly wrong, it does copy, depending on what kind of indexing is used. You'd have to show what exactly `subset_...` is. See also https://stackoverflow.com/questions/30238092/numpy-slice-an-array-without-copying-it – mkrieger1 May 01 '19 at 15:14
  • Indexing with slices (`basic indexing`) produces a `view`. Advanced indexing (e.g. with a list of indices) produces a copy. Your operation has to make the copy before freeing up the old memory (that's assuming there aren't other views of the same base). – hpaulj May 01 '19 at 16:01

0 Answers0