Utility of parameter 'out' in numpy functions

后端 未结 1 1157
暖寄归人
暖寄归人 2021-01-17 09:34

What is the utility of the out parameter in certain numpy functions such as cumsum or cumprod or other mathematical funct

相关标签:
1条回答
  • 2021-01-17 10:15

    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.

    0 讨论(0)
提交回复
热议问题