May-08-2018, 05:20 PM
if you have an array like arr = np.array([1,2,3,4,5]) and you would say something like arr[1:3] you would select everything starting at index 1 to index 3 (but excluding index 3). so you would get [2,3]. so the : always tells the array from where to where you want to select stuff. additionally you could say something like arr[0:4:2] now you pick everything from index 0 to index 4 (excluding index 4) and only every two values (so you set a step width there). what you would get is: [1,3].
In your example you have a 2 Dimensional array, so saying something like ridership[1,3] would select the item at row 1 and column 3. so you divide your x,y,z,... indices by using "," comma. so in your case you would pick following rows [1:3] (so each row from index 1 to 3, excluding index 3) and columns [3:5] (so each column from 3 to 5, excluding index 5) since you selece ridership[1:3, 3:5]. ridership[1,3] == 2328, ridership[1,4] == 2539, ridership[2,3] == 6461 and ridership[2,4] == 2691. What you are doing is slicing your array and it is extreamly efficient in comparison to the usage of loops :)
In your example you have a 2 Dimensional array, so saying something like ridership[1,3] would select the item at row 1 and column 3. so you divide your x,y,z,... indices by using "," comma. so in your case you would pick following rows [1:3] (so each row from index 1 to 3, excluding index 3) and columns [3:5] (so each column from 3 to 5, excluding index 5) since you selece ridership[1:3, 3:5]. ridership[1,3] == 2328, ridership[1,4] == 2539, ridership[2,3] == 6461 and ridership[2,4] == 2691. What you are doing is slicing your array and it is extreamly efficient in comparison to the usage of loops :)