Q:

Write a NumPy program to make an array immutable (read-only)

0

Write a NumPy program to make an array immutable (read-only)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.zeros(10)
x.flags.writeable = False
print("Test the array is read-only or not:")
print("Try to change the value of the first element:")
x[0] = 1

Sample Output:

Test the array is read-only or not:                                    
Try to change the value of the first element:                          
Traceback (most recent call last):                                     
  File "24222080-0d5f-11e7-93ad-ebc5bbb63894.py", line 6, in   
    x[0] = 1                                                           
ValueError: assignment destination is read-only

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now