Guided Notes

Copy vs View & Iterating

When arrays share memory, the base attribute, and looping with nditer and ndenumerate.

Copies and views

Slide 1 / 5

Some operations create a copy β€” a new array with its own data. Others create a view β€” a new array object that looks at the same data as the original.

β€’ A copy owns its data: changing it never affects the original. β€’ A view doesn't own its data: changing the view changes the original, and vice versa.

Views make NumPy fast and memory-efficient, because slicing a huge array doesn't duplicate it. But they can surprise you.

← Indexing & Slicing