-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopying_array.py
More file actions
executable file
·42 lines (36 loc) · 1.47 KB
/
copying_array.py
File metadata and controls
executable file
·42 lines (36 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from numpy import *
arr = array([1,2,3,4,5])
arr1 = array([6,7,8,9,10])
arr3 = arr+5
arr4 = arr+arr1 # vECTORIZED OPERATIONS
print(arr3)
print(arr4)
print(sin(arr))
print(log(arr), sqrt(arr))
print(min(arr1),max(arr1))
print(concatenate([arr,arr1]))
#------------------------------------------------------------------------------------#
# Copying the arrays
arr5 = arr1
print(arr1)
print(arr5)
print(id(arr5),id(arr1))
# It is called the alising bcz both array are pointing to the same address
#------------------------------------------------------------------------------------#
# Copying the array with the different addres
#------------------------------------------------------------------------------------#
'''
Types of Cpoying in the Python :
1. Shallow Copy : Copy the element but both the array are still dependent on each other
2. Deep Copy :
'''
arr6 = arr.view() # create the array at the different address , but elements points to the same object in memory
arr[1]= 7 # changes both array due to shallow copy
print(arr6,arr, id(arr6), id(arr))
#------------------------------------------------------------------------------------#
# Deep Copy
#------------------------------------------------------------------------------------#
arr6 = arr.copy() # create the array at the different address
arr[1]= 8 # changes only the arr array due to Deep copy
print(arr6,arr, id(arr6), id(arr))
#------------------------------------------------------------------------------------#