Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introduction to NumPy Meet NumPy Creating the Study Log

Cody Stephenson
Cody Stephenson
8,272 Points

How are we able to update the daily minutes entries in the array after it has been created if arrays are immutable?

The array is created with all zeros in a previous cell - then we are able to change entries by index in a later cell. This seems contrary to arrays being immutable? Or is it strictly the size and datatype that are immutable?

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 68,031 Points

Hey Cody Stephenson, arrays are mutable. There is a writable flag that can be set to raise an error on a write attempt. The does not stop the ability of previous references to the array from writing to elements.

So a slice created before setting writable to False, is not blocked. “...locking a base object does not lock any views that already reference it”. See docs under writable. https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flags.html