blueSurfer
blueSurfer

Reputation: 5821

Memory use during recursion in Python

I've implemented a recursive function which takes as parameter a numpy array. Here the simplified version:

 def rec(arr):

     rec(arr[indices])

In every recursive call I use a part of the array indexed by some indices.

My question is about the memory load: how does python handle this? Does it makes a copy of the array at each call or not?

Upvotes: 1

Views: 1578

Answers (1)

NPE
NPE

Reputation: 500247

It depends on the nature of indices. If it's a slice, there is no copy. If, on the other hand, you're using fancy indexing, then a copy is made.

I recommend reading Copies and Views in the NumPy tutorial (even though the section does not cover fancy indexing).

Upvotes: 6

Related Questions