Issue
I am trying to take a 3*3 subset from a really large 400 x 500 ndarray of numpy. But due to some reason, I am not getting the desired result. Rather it is taking the first three rows as a whole.
Here is the code that I wrote.
subset_matrix = mat[0:3][0:3]
But this is what I am getting in my output of my Jupyter Notebook
array([[91, 88, 87, ..., 66, 75, 82],
[91, 89, 88, ..., 68, 78, 84],
[91, 89, 89, ..., 72, 80, 87]], dtype=uint8)
Solution
mat[0:3][0:3]
slice the axis 0 of the 2D array twice and is equivalent to mat[0:3]
. What you need is mat[0:3,0:3]
.
Answered By - Jérôme Richard
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.