Why is there a difference in the following operations, How are they implemented in the library?
print(prov_img[:19][:20].shape)
Output : (19, 1250)
print(prov_img[:19,:20].shape)
Output : (19, 20)
prov_img
is a 2d array here.
This code snippet is providing you the first 19 rows (0th row to 18th row) and 20 columns (0th column to 19th column) of prov_img
:
>>> prov_img[:19,:20].shape
(19, 20)
Here, prov_img[:19]
gives you the first 19 rows of prov_img
and then adding [:20]
means you are again taking the first 20 rows from the matrix you got from prov_img[:19]
:
>>> prov_img[:19][:20].shape
(19, 1250)
Since there are 19 rows in prov_img[:19]
, slicing the first 20 rows from it eventually providing you all the 19 rows. There is no slicing in columns and as a result you are getting output as (19, 1250)
where 1250 is the number of columns in your prov_img
matrix (2d array).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With