Python: Slicing lists
Nevermind I understand it now
More on reddit.comHelp w slicing array distinctions
This is because the two expressions mean different things. You can think about a two-dimensional array as an array of arrays, something like this:
[
[_, _, _],
[_, _, _],
[_, _, _],
]
When you use the subscript you use, (btw. 0 is not necessary there and might be a bit confusing: a[0:, 2] == a[:, 2]), you say this:
Select all rows and then select the third element
and this is what gets selected:
[
[_, _, _],
[_, _, _],
[x, x, x],
]
However, when you do a[:, 2:], you are saying:
Select all rows, and then select the last column
And this is selected:
[
[_, _, x],
[_, _, x],
[_, _, x],
]
You would've been right to assume that these two should do the same, had it not being for the "direction" of rows.
More on reddit.comSlicing numpy array
This is just convention; it's inconvenient in some places and convenient in others.
Your confusion is the result of forcing what you learned in math about matrices onto numpy arrays. Don't do that. They look similar in some cases but are very different. For example, there is no shape (,4)[1]. Column vectors don't exist. You can have an array that is four rows each of length 1 which may look like a column vector but it isn't (really, since it's 2d). It's an array of shape (4, 1). So why don't you get an array of that shape from slicing a column? Convention. That's all.
[1] This is just an artifact of Python's notation for tuples. We would like the tuple of length 1 that contains the number 4 to be (4) but if we want parentheses to behave like they do in math that has to just be the number 4. So if you want a length-1 tuple you need a comma after the first and only element. This also means that while an empty list is [], an empty tuple is (,).
Slicing 2D arrays with Numpy
Can you try asking a question? I don't see any question marks here
More on reddit.com