-3

I was trying to read the numpy indexing docs, but was still unclear on why this is the case. Is the behavior mentioned in the title just a convention, or is there some underlying design decision I'm missing?

Thanks.

3
  • Do you understand the (3,) tuple? Commented Aug 24, 2020 at 18:30
  • v[:,:] has two dimensions with sizes (1, 3), while v[0,:] is just the first element in the first dimension of v, which has one dimension size 3 Commented Aug 24, 2020 at 18:32
  • v[0,:] is an example of integer basic indexing. That's the previous docs section to the one you linked. "An integer, i, returns the same values as i:i+1 except the dimensionality of the returned object is reduced by 1." Commented Aug 24, 2020 at 19:39

1 Answer 1

0

It is because you are selecting/slicing a single row and you getting all elements from that row with a shape of (3,). The second method is looking for all rows even though it is only going to return one row, it is going to shape the output as rows hence (1,3) shape.

See this post for images. https://stackoverflow.com/a/55581845/6361531

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.