How to make a NumPy array read-only? Last Updated : 04 Nov, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 writable flag of the NumPy array to false. Syntax: array.flags.writable=False This set the writable flag to false and hence array becomes immutable i.e read-only. See the example below Example: Python import numpy as np a = np.zeros(11) print("Before any change ") print(a) a[1] = 2 print("Before after first change ") print(a) a.setflags(write=False) print("After making array immutable on attempting second change ") a[1] = 7 Output: 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[1]=7 ValueError: assignment destination is read-only Comment More infoAdvertise with us Next Article How to make a NumPy array read-only? S shivanshsaxena1 Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads How to Swap Two Rows in a NumPy Array One common task you might encounter when working with NumPy arrays is the need to swap two rows. Swapping rows can be essential in data preprocessing, reshaping data, or reordering data to perform specific analyses in Python. In this article, we will explore different methods to swap two rows in a N 4 min read How To Save Multiple Numpy Arrays NumPy is a powerful Python framework for numerical computing that supports massive, multi-dimensional arrays and matrices and offers a number of mathematical functions for modifying the arrays. It is an essential store for Python activities involving scientific computing, data analysis, and machine 3 min read How to Convert NumPy Matrix to Array In NumPy, a matrix is essentially a two-dimensional NumPy array with a special subclass. In this article, we will see how we can convert NumPy Matrix to Array. Also, we will see different ways to convert NumPy Matrix to Array. Convert Python NumPy Matrix to an ArrayBelow are the ways by which we can 3 min read NumPy save() Method | Save Array to a File The NumPy save() method is used to store the input array in a binary file with the 'npy extension' (.npy). Example: Python3 import numpy as np a = np.arange(5) np.save('array_file', a) SyntaxSyntax: numpy.save(file, arr, allow_pickle=True, fix_imports=True) Parameters: file: File or filename to whic 2 min read How To Resolve Numpy'S Memory Error One common challenge that users encounter is the dreaded NumPy Memory Error. This error occurs when the library is unable to allocate sufficient memory to perform the requested operation. In this article, we will see how to resolve NumPy MemoryError in Python. What is Numpy's Memory Error?NumPy's Me 3 min read Like