Can someone please explain how come we converted a 4D array to 3D through these steps?
The command below (#1) should output a 4D array while the one below it (#2) would output a 3D array.
(1) a_prev_pad = A_prev_pad[i,:,:,:]
(2) a_slice_prev = a_prev_pad[vert_start:vert_end,horiz_start:horiz_end,:]
The code does not throw any error when these commands are run.
Sure: you have just fixed the value of the first dimension to select one of the samples. That single sample is an individual image which has 3 remaining dimensions: height, width and channels.
The dimensions of the 4D arrays here are:
samples x height x width x channels
The loops are structured to handle each sample individually.
As Paul said:
“The dimensions of the 4D arrays here are:”
samples x height x width x channels
Here, samples are more than one.
Now check the dimensions of the 3D arrays, which are:
sample x height x width x channels
Here, sample is just one.
We can further convert it to 2D like this:
sample x height x width x channel
Here, sample and channel both are equal to one.
Best,
Saif.
Thanks Paulin! I understand that. However, my question is how does Python know that the first value is a reference value (i.e. refers to an example) and not something else. I understand that is how we have declared it but I could not understand how does Python understand this. For example, if we take a value of i as 4. The a_prev_pad would have shape as (4,:,:,:). In this case, the first index, which is 4, could refer to anything such as a number of columns, number of rows, etc as opposed to a particular fixed value.
Here i
is used for the number of samples. If i = 4, it means we are dealing with 4th sample (sample is still one, the 4th one).
No, the point is that 4 is a particular fixed value, right?