Reputation: 12567
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?
Upvotes: 5
Views: 867
Reputation: 281252
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.
Upvotes: 4