views and copiesΒΆ
Sometimes, even after five years using NumPy, I have to go with my gut feeling to predict if an operation will trigger a copy in the underlying data. – NumPy developer
When NumPy returns an array, it may be the same array (a view) or a new one (a copy).
There’s nothing obvious to tell which you’re getting, but the difference can change how the code behaves. Returning a view is faster because there’s no copying step. But a view is the gift that keeps on giving – if either side changes a cell, it silently changes for both.
- `Are there functions guaranteed to return one or the other?`_
- `Is there a rule to figure out which one Function X will return?`_
- `Can I turn a view into a copy?`_
- `Can I turn a copy into a view?`_
- `When can I ignore the difference?`_
- `Is there a way for code to tell me which one I’ve gotten?`_
- `Are there slick uses for one or the other?`_
- `What’s the deal with Pandas’ SettingWithCopyWarning?`_
- `Where can I find a more detailed explanation?`_