Exercise · NumPy and pandas · lesson 7 of 12
Exercise: values above the column mean
Write a function above_mean_counts(X): it takes a two-dimensional numpy array and returns a one-dimensional array. For each column of X, it holds the number of values in that column that are greater than the column's mean.
above_mean_counts(np.array([[1, 10], [5, 20], [6, 90]]))→[2, 1]above_mean_counts(np.array([[1], [2], [3]]))→[1]above_mean_counts(np.array([[4, 1], [4, 2], [4, 6]]))→[0, 1]
Constraints: X has at least one row, and its values may be negative or fractional; a value equal to the mean is not counted; the result's length equals the number of columns.
The "Run tests" button runs the checks from the test_above_mean.py tab—you can read them but not change them.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.