Utility of parameter 'out' in numpy functions Utility of parameter 'out' in numpy functions numpy numpy

Utility of parameter 'out' in numpy functions


Functions that take the out parameter create new objects. This is usually what you would expect from the function: Give some array and get a new one with the transformed data.

However, imagine you want to call this function several thousand times in a row. Each function call will create a new array, which of course takes a lot of time.

In this case you may want to create an output array out and let the function fill the array with the output. After processing the data you can reuse out and let the function overwrite its values. This way you won't allocate or free any memory, which can save you a lot of time.