Reducing Along an Axis
~10 mincode completion
Write feature_means(X) that returns the mean of each column of a 2-D array, so one number per feature.
For [[1, 2], [3, 4]] it returns [2.0, 3.0].
Examples
Two samples, two features: one mean per feature
- Input
- feature_means([[1, 2], [3, 4]])
- Output
- [2, 3]
Three samples averaged per feature
- Input
- feature_means([[0, 10], [0, 20], [3, 30]])
- Output
- [1, 20]
Hints
Hint 1
The reduction runs down the columns, so pass .
Hint 2
Watch for this: used axis one.
Requirements
X: a 2-D array of shape (n_samples, n_features)Return a 1-D array of length n_features.
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Where this shows up
~10 min
••••••••••••••••
8 employers weight this skill
3 quant funds, 2 big tech firms, 1 frontier lab, 1 autonomy company, 1 enterprise vendor. Top match scores 81.
Python
import numpy as np
def feature_means(X):
"""
Mean of each column.
Args:
X: a 2-D array of shape (n_samples, n_features)
Returns:
A 1-D array of length n_features.
"""
# YOUR CODE HERE
pass