Python Forum
Extract of matrix subpart using a deep copy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extract of matrix subpart using a deep copy
#1
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

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]])
Reply


Messages In This Thread
Extract of matrix subpart using a deep copy - by paul18fr - May-01-2019, 09:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Deep Learning Book ankitdixit 2 2,748 Feb-06-2020, 12:01 PM
Last Post: buran
  h5py: deep dataset access paul18fr 2 2,407 Nov-28-2019, 03:43 PM
Last Post: paul18fr
  Free ebook "Deep Learning with PyTorch" ThomasL 0 2,354 Nov-22-2019, 02:50 PM
Last Post: ThomasL
  3D Object Recognition using Deep Learning chandininair 0 2,265 Aug-08-2018, 11:29 PM
Last Post: chandininair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020