May-08-2018, 05:21 PM
Try to put your code in [python][/python] markers or the indent is lost...
The answer is correct, you need to take into account 2 important aspects of python (and numpy):
- The indexes start to count at 0
- The ranges never reach the latest value, so 1:4 is 1, 2, and 3
So when you say ridership[1:3, 3:5] you are asking for the elements from row 1 to 3 excluded (so 2nd and 3rd rows) and columns from 3 to 5 excluded (so columns 4th and 5th)
If this feels strange, it is really powerful... the reason to not to include the upper bound of a slice is obvious when you notice that in that way is:
The answer is correct, you need to take into account 2 important aspects of python (and numpy):
- The indexes start to count at 0
- The ranges never reach the latest value, so 1:4 is 1, 2, and 3
So when you say ridership[1:3, 3:5] you are asking for the elements from row 1 to 3 excluded (so 2nd and 3rd rows) and columns from 3 to 5 excluded (so columns 4th and 5th)
If this feels strange, it is really powerful... the reason to not to include the upper bound of a slice is obvious when you notice that in that way is:
a[0:3] + a[3:10] == a[0:10]And that helps a lot to avoid missing or repeating elements wen playing with lists or matrices.