Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCody Stephenson
8,361 PointsHow 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
Treehouse Moderator 68,454 PointsHey 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