简体   繁体   中英

Does Numpy allocate temporary arrays in expressions like x += 2 * y?

When evaluating expressions like

x += 2 * y

does Numpy first allocate a new temporary array to hold 2*y , add it to x and then delete it, or can it perform this whole operation in-place?

Yup, that makes a temporary array.

If you find yourself needing to mitigate NumPy's love of giant scratch arrays, additional libraries like Numexpr can help quite a bit, but make sure you're attributing performance problems to the right causes. Naive attempts to save allocations usually cause massive slowdowns instead of performance improvement.

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