May-01-2019, 09:17 PM
Hi,
I remember that in Python "A = B" corresponds to a "shallow" copy; in other word if I change any cell in B, then the same cell is modified in A.
I'm trying to extract rows in B using a deep copy at the same time; between the 2 following trials, the structure of the 2 arrays is different (1 more dimension in the trial 1): why such behaviour?
What's the correct syntax?
Thanks
Paul
Second matrix: dimension here (12,10)
I remember that in Python "A = B" corresponds to a "shallow" copy; in other word if I change any cell in B, then the same cell is modified in A.
I'm trying to extract rows in B using a deep copy at the same time; between the 2 following trials, the structure of the 2 arrays is different (1 more dimension in the trial 1): why such behaviour?
What's the correct syntax?
Thanks
Paul
import numpy as np A = np.random.randint(10, size = (100,10), dtype = np.int); index = np.where(A[:,0] == 1); Extract_trial1 = np.copy(A[index,:]); del index; Extract_trial2 = np.copy(A); index = np.where(A[:,0] != 1); Extract_trial2 = np.delete(Extract_trial2,index,axis=0);First matrix: dimension here (1,12,10)
Quote:array([[[1, 6, 1, 5, 0, 4, 8, 2, 4, 3],
[1, 7, 7, 3, 8, 9, 2, 8, 7, 8],
[1, 3, 7, 9, 3, 1, 2, 2, 8, 8],
[1, 9, 5, 7, 9, 5, 2, 3, 2, 5],
[1, 2, 0, 8, 9, 4, 7, 2, 0, 1],
[1, 3, 4, 4, 4, 6, 6, 1, 0, 4],
[1, 8, 1, 4, 2, 7, 0, 6, 9, 0],
[1, 1, 6, 3, 1, 4, 3, 2, 2, 4],
[1, 8, 0, 4, 2, 7, 1, 3, 7, 5],
[1, 4, 7, 9, 0, 2, 1, 4, 5, 2],
[1, 5, 6, 8, 9, 2, 0, 4, 6, 6],
[1, 6, 2, 4, 4, 2, 3, 2, 1, 2]]])
Second matrix: dimension here (12,10)
Quote:array([[1, 6, 1, 5, 0, 4, 8, 2, 4, 3],
[1, 7, 7, 3, 8, 9, 2, 8, 7, 8],
[1, 3, 7, 9, 3, 1, 2, 2, 8, 8],
[1, 9, 5, 7, 9, 5, 2, 3, 2, 5],
[1, 2, 0, 8, 9, 4, 7, 2, 0, 1],
[1, 3, 4, 4, 4, 6, 6, 1, 0, 4],
[1, 8, 1, 4, 2, 7, 0, 6, 9, 0],
[1, 1, 6, 3, 1, 4, 3, 2, 2, 4],
[1, 8, 0, 4, 2, 7, 1, 3, 7, 5],
[1, 4, 7, 9, 0, 2, 1, 4, 5, 2],
[1, 5, 6, 8, 9, 2, 0, 4, 6, 6],
[1, 6, 2, 4, 4, 2, 3, 2, 1, 2]])