Difference Between Reference, View and Copy Function in NumPy
Machine Learning courses with 100+ Real-time projects Start Now!!
Program 1
import numpy as np
ar=np.arange(1,11,1)
print(ar)
print("Address of My Array-:",id(ar))
ar_ref=ar
print(ar_ref)
print("Address of My Reference Array-:",id(ar))
ar[3]=500
ar_ref[5]=800
print("After Change: ")
print(ar)
print(ar_ref)Program 2
import numpy as np
ar=np.arange(1,11,1)
print(ar)
print("Address of My Array-:",id(ar))
arv=ar.view()
print("Address of My View-:",id(arv))
print(arv)
ar[3]=700
arv[6]=800
print("After Change: ")
print(ar)
print(arv)Program 3
import numpy as np
ar=np.arange(1,11,1)
print(ar)
print("Address of My Array-:",id(ar))
arc=ar.copy()
print("Address of My Copied Array-:",id(arc))
print(arc)
ar[3]=600
arc[7]=900
print("After change")
print(ar)
print(arc)
Your opinion matters
Please write your valuable feedback about DataFlair on Google

