简体   繁体   中英

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM