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)

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *