How to Check If a View Changes When Original NumPy Array Changes


In this example we will show how to create a view and check if the view changes when the original NumPy array changes in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4])
view_n = n.view()
print(view_n)

n[2] = 10

# any changes made to the original array will affect the view
print(n)
print(view_n)

Output:

[1 2 3 4]
[ 1  2 10  4]
[ 1  2 10  4]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments