import numpy as np
a = np.arange(12) #a For a sequence
b = a # No new objects have been created
print('a Of shape by :', a.shape) # Output a The size of the
print('b yes a Do you ?', b is a) #ab Two names for the same object
b.shape = 3, 4 # take b Of shape change
print('a Of shape Turn into :', a.shape) #a Of shanpe And it changed
Output results :
a Of shape by : (12,)
b yes a Do you ? True
a Of shape Turn into : (3, 4)
Different array objects can type the same data ,view Method to create a new object that is the same as the original array .
a = np.arange(12)
c = a.view() # Build a and a Same c
print('c When not changed a Of shape by :', a.shape) # Output a The size of the
print('c yes a Do you ?', c is a)
print('c In order to a Based on it ', c.base is a)
c.shape = 3, 4
print('c After change a Of shape by :', a.shape)
Output results :
c When not changed a Of shape by : (12,)
c yes a Do you ? False
c In order to a Based on it True
c After change a Of shape by : (12,)
This is the time d yes a Copy , Just a simple copy , There's nothing to do with the two :
a = np.arange(12)
d = a.copy() # Build a and a Same c
print('d yes a Do you ?', d is a)
print('d In order to a Based on it ', d.base is a)
Output results :
d yes a Do you ? False
d In order to a Based on it False