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
#2
In case of Extract_trial1, when you invoke A[index, :] it triggers advanced indexing of Numpy.
You can read about advanced indexing [here](https://docs.scipy.org/doc/numpy/referen...exing.html).
Adv. indexing always returns a copy of the data, so using np.copy is redundant here. Advanced indexing
is triggered because you pass an array of integers to A[...].

From official docs:

Output:
Advanced indexing is triggered when the selection object, obj, is a non-tuple sequence object, an ndarray (of data type integer or bool), or a tuple with at least one sequence object or ndarray (of data type integer or bool).
You can inspect this by printing shape of the index variable (it is randomly changed between runs):

index = np.where(A[:,0] == 1)
print(np.array(index).shape)
Lets look at the advanced indexing broadcasting formula:

result[i_1, ..., i_M] == x[ind_1[i_1, ..., i_M], ind_2[i_1, ..., i_M], ..., ind_N[i_1, ..., i_M]]
ind_1 is your index variable, (ind_2 = ':' in your case, that is simple indexing); ind_1 has shape (1, small random integer), so result shape will be (1, small_random_integer, 10). This is what you are having regarding Extract_trial1.

You can try the following examples:

 A[[1,2,3], :] => shape = (3, 10)
 A[[[1,2,3],], :] => shape (1, 3, 10)
 A[[[[1,2,3],]], :] => shape (1, 1, 3, 10)
To fix this behavior you need to pass 1d array of indices to A[...], i.e. A[index[0], :].
Reply


Messages In This Thread
RE: Extract of matrix subpart using a deep copy - by scidam - May-02-2019, 01:19 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Star [HELP] The Application of Deep Neural Networks MistyhV1 0 148 May-05-2024, 02:22 PM
Last Post: MistyhV1
  Deep Learning Book ankitdixit 2 2,792 Feb-06-2020, 12:01 PM
Last Post: buran
  h5py: deep dataset access paul18fr 2 2,460 Nov-28-2019, 03:43 PM
Last Post: paul18fr
  Free ebook "Deep Learning with PyTorch" ThomasL 0 2,379 Nov-22-2019, 02:50 PM
Last Post: ThomasL
  3D Object Recognition using Deep Learning chandininair 0 2,280 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