NumPy Array Copy Vs View
NumPy Array Copy Vs View
Dark mode
Dark code
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP BOOTSTRAP HOW TO W3.CSS C C++ C# REACT R JQUERY DJANGO
NumPy HOME
NumPy Intro
NumPy Getting Started
The view does not own the data and any changes made to the view will affect the original array, and any changes made to the
NumPy Random original array will affect the view.
Random Intro
Data Distribution
Random Permutation
COPY:
Seaborn Module
Normal Distribution
Binomial Distribution
Example Get your own Python Server
Make a copy, change the original array, and display both arrays:
import numpy as np
print(arr)
print(x)
Try it Yourself »
COLOR PICKER
The copy SHOULD NOT be affected by the changes made to the original array.
VIEW:
Example
Make a view, change the original array, and display both arrays:
import numpy as np
print(arr)
print(x)
Try it Yourself »
The view SHOULD be affected by the changes made to the original array.
Example
Make a view, change the view, and display both arrays:
import numpy as np
print(arr)
print(x)
Try it Yourself »
The original array SHOULD be affected by the changes made to the view.
ADVERTISEMENT
Every NumPy array has the attribute base that returns None if the array owns the data.
Example
Print the value of the base attribute to check if an array owns it's data or not:
import numpy as np
x = arr.copy()
y = arr.view()
print(x.base)
print(y.base)
Try it Yourself »
Exercise:
Use the correct method to make a copy of the array.
x = arr.
Submit Answer »
ADVERTISEMENT
ADVERTISEMENT
FORUM | ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we
cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.