numpy array([[-13,-38,22,-41,25], [-45,29,14,-34,-49], [26,21,-44,-25,0], [-30,-32,34,-39,-22], [-21,-36,0,18,37], [37,44,46,36,-37]]) extract the slices [[-30,-32,34,-39,-22], [-45,29,14,-34,-49], [-21,-36,0,18,37]] extract the elements [25,34,46,-36] extract the slices [14,-34,-49], [-44,-25,0], [34,-39,-22] Mean of the numbers in each array of the first dimension Sample standard deviation of numbers in each index position of the second dimension Use a mask to find the mean of the negative numbers in the array
numpy array([[-13,-38,22,-41,25], [-45,29,14,-34,-49], [26,21,-44,-25,0], [-30,-32,34,-39,-22], [-21,-36,0,18,37], [37,44,46,36,-37]])
extract the slices [[-30,-32,34,-39,-22], [-45,29,14,-34,-49], [-21,-36,0,18,37]]
extract the elements [25,34,46,-36]
extract the slices [14,-34,-49], [-44,-25,0], [34,-39,-22]
Mean of the numbers in each array of the first dimension
Sample standard deviation of numbers in each index position of the second dimension
Use a mask to find the mean of the negative numbers in the array
Input: A NumPy array, arr
1. Extract the slices [[-30, -32, 34, -39, -22], [-45, 29, 14, -34, -49], [-21, -36, 0, 18, 37]]:
- slices = arr[[3, 1, 4]]
2. Extract the elements [25, 34, 46, -36]:
- elements = arr[[0, 3, 5], [4, 2, 2]]
3. Extract the slices [14, -34, -49], [-44, -25, 0], [34, -39, -22]:
- slices2 = arr[1:4, 2:5]
4. Calculate the mean of the numbers in each array of the first dimension:
- mean_axis0 = np.mean(arr, axis=0)
5. Calculate the sample standard deviation of numbers in each index position of the second dimension:
- std_axis1 = np.std(arr, axis=1, ddof=1)
6. Use a mask to find the mean of the negative numbers in the array:
- mask = arr < 0
- mean_negatives = np.mean(arr[mask])
Output:
- Extracted Slices (slices)
- Extracted Elements (elements)
- Extracted Slices 2 (slices2)
- Mean of Numbers in Each Array of the First Dimension (mean_axis0)
- Sample Standard Deviation of Numbers in Each Index Position of the Second Dimension (std_axis1)
- Mean of Negative Numbers in the Array (mean_negatives)
Step by step
Solved in 3 steps with 2 images