Python to create a view() and copy() of NumPy arrays
kodingwindow@kw:~$ python3 ... >>> from numpy import * >>> arr1 = array([1, 2, 3, 4, 5]) >>> arr2 = arr1.view() >>> arr1 array([1, 2, 3, 4, 5]) >>> arr2 array([1, 2, 3, 4, 5]) >>> arr2[0] = 100 >>> arr2 array([100, 2, 3, 4, 5]) >>> arr1 array([100, 2, 3, 4, 5])
>>> arr1 = array([1, 2, 3, 4, 5]) >>> arr2 = arr1.copy() >>> arr1 array([1, 2, 3, 4, 5]) >>> arr2 array([1, 2, 3, 4, 5]) >>> arr2[0] = 100 >>> arr2 array([100, 2, 3, 4, 5]) >>> arr1 array([1, 2, 3, 4, 5])
What Next?
Python NumPy Arrays Comparison
Python NumPy Mathematical Functions for Arrays
Python indexing and slicing on NumPy arrays
Advertisement