<jupyter_start><jupyter_text>Working with Arrays  1. Run the following cells:<jupyter_code>import numpy as np
array_1D = np.array([10,11,12,13, 14])
array_1D
array_2D = np.array([[20,30,40,50,60], [43,54,65,76,87], [11,22,33,44,55]])
array_2D
array_3D = np.array([[[1,2,3,4,5], [11,21,31,41,51]], [[11,12,13,14,15], [51,52,53,54,5]]])
array_3D<jupyter_output><empty_output><jupyter_text>2. Slice the first column of the 2-D array.<jupyter_code>array_2D[:,0]<jupyter_output><empty_output><jupyter_text>3. Slice the last column of the 2-D array<jupyter_code>array_2D[:,-1]<jupyter_output><empty_output><jupyter_text>4. Slice the second row of the 2-D array<jupyter_code>array_2D[1,:]
#array_2D[1]<jupyter_output><empty_output><jupyter_text>5. Slice the last two columns of the 2-nd row of the 2-D array<jupyter_code>array_2D[1,-2:]<jupyter_output><empty_output><jupyter_text>6. Slice the 2-nd row of the 2-D array excluding the last two columns<jupyter_code>array_2D[1,:-2]<jupyter_output><empty_output><jupyter_text>7. Slice everything excluding the first row and last column of the 2-D array<jupyter_code>array_2D[1:,:-1]<jupyter_output><empty_output><jupyter_text>8. Slice the 1st, 3rd and 5th columns of the 2-D array   (Hint: Take advantage of the [start:stop:step] suntax of indices)<jupyter_code>array_2D[:,0::2]<jupyter_output><empty_output><jupyter_text>9. Slice the first columns of both matrices in the 3-D array   (Hint: The syntax for the indices of the 3-D array is the following: [subarray, row, column])<jupyter_code>array_3D[:,:,0]<jupyter_output><empty_output><jupyter_text>10. Slice every other column of both matrices in the 3-D array<jupyter_code>array_3D[:,:,::2]<jupyter_output><empty_output><jupyter_text>11. Use conditional slicing to check if the individual elements of each array satisfy a given condition (e.g. greater than 10)<jupyter_code>array_1D > 10
array_2D > 10
array_3D > 10<jupyter_output><empty_output><jupyter_text>12. Use conditional slicing to display which individual elements of each array satisfy this condition<jupyter_code>array_1D[array_1D > 10]
array_2D[array_2D > 10]
array_3D[array_3D > 10]<jupyter_output><empty_output><jupyter_text>13. Add a second condition and disaply which individual elements satisfy both (e.g. greater than 10 and odd)   (Hint: Odd numbers leave a remainder of 1, when dividing by 2. Hence, we can use "%" to express this condition.)<jupyter_code>array_1D[((array_1D > 10) & (array_1D % 2 == 1))]
array_2D[((array_2D > 10) & (array_2D % 2 == 1))]
array_3D[((array_3D > 10) & (array_3D % 2 == 1))]<jupyter_output><empty_output><jupyter_text>13. Loosen up the requirements, so that either condition works   (Hint: We just need to go from condition_1  and  condition_2 to condition_1  or  condition_2)<jupyter_code>array_1D[((array_1D > 10) | (array_1D % 2 == 1))]
array_2D[((array_2D > 10) | (array_2D % 2 == 1))]
array_3D[((array_3D > 10) | (array_3D % 2 == 1))]<jupyter_output><empty_output><jupyter_text>14. Call the first row of the first 2-D array in the 3-D array in 3 different ways:    A) Use precise indices for both dimensions.     B) Use a precise index for one dimension and a slice for the second dimension.     C) Uses slices (from the origin, up to the second value) for both dimensions.<jupyter_code>array_3D[0,0]
array_3D[:1,0]
array_3D[:1,:1]<jupyter_output><empty_output><jupyter_text>15. Check the shapes of the 3 different notations calling the same values<jupyter_code>array_3D[0,0].shape
array_3D[:1,0].shape
array_3D[:1,:1].shape<jupyter_output><empty_output><jupyter_text>16. Since the last two outputs contain excess dimensions, use the squeeze function to reduce them<jupyter_code>np.squeeze(array_3D[:1,0])
#array_3D[:1,0].squeeze()
np.squeeze(array_3D[:1,:1])
#array_3D[:1,:1].squeeze()<jupyter_output><empty_output><jupyter_text>17. Now check the shapes of the reduced outputs<jupyter_code>np.squeeze(array_3D[:1,0]).shape
np.squeeze(array_3D[:1,:1]).shape<jupyter_output><empty_output>