Let’s discuss how to make NumPy array immutable i.e that can not be rewritten or can’t be changed. This can be done by setting a writeable flag of the NumPy array to false.
This set the writable flag to false and hence array becomes immutable i.e read-only. See the example below
Before any change [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Before after first change [0. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0.] After making array immutable on attempting second change Traceback (most recent call last): File "gfg9.py", line 11, in <module> a=7 ValueError: assignment destination is read-only
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course