Implement a NumPy function that drops every value strictly above a fixed cap and returns the mean of the remaining elements. It tests boolean masking, the boundary rule at the cap, and the difference between removing outliers and winsorizing them in an experiment readout.
Implement `def filter_bots_and_mean(values: np.ndarray, cap: float) -> float` in `solution.py`. Drop every element strictly greater than `cap`, then return the arithmetic mean of the remaining elements.
Requirements:
- Elements equal to `cap` are kept.
- Remove outliers entirely: do not winsorize or clip to `cap`.
- Return a `float`.
Example:
```python
filter_bots_and_mean(np.array([1,2,2,3,3,3,4,4,5,100.0]), 50.0)
# drops 100.0, mean of remaining 9 values == 3.0
```
```hint Boolean mask
A comparison on a NumPy array gives a boolean array you can index with. Check which comparison operator keeps an element that equals the cap.
```
### Constraints & Assumptions
- `values` is a 1-D numeric array.
- At least one element survives the filter.
### What a Strong Answer Covers
- The boundary rule: an element equal to `cap` stays in the sample.
- Removed elements leave both the sum and the count, so the mean is taken over survivors only.
- A vectorized implementation and its time and space cost.
- The return type, and what happens on edge inputs such as an empty result or NaN values.
### Follow-up Questions
- How would you handle the readout if every element could be filtered out?
- When would you cap on a fixed threshold, and when on a percentile such as p99?
- If the treatment itself changes how many units exceed the cap, what does filtering do to the comparison between experiment arms?
Overview: Implement a NumPy function that drops every value strictly above a fixed cap and returns the mean of the remaining elements. It tests boolean masking, the boundary rule at the cap, and the difference between removing outliers and winsorizing them in an experiment readout.
Implement def filter_bots_and_mean(values: np.ndarray, cap: float) -> float in solution.py. Drop every element strictly greater than cap, then return the arithmetic mean of the remaining elements.
Requirements:
Elements equal to
cap
are kept.
Remove outliers entirely: do not winsorize or clip to
cap
.
Return a
float
.
Example:
filter_bots_and_mean(np.array([1,2,2,3,3,3,4,4,5,100.0]), 50.0)
# drops 100.0, mean of remaining 9 values == 3.0
Constraints & Assumptions
values
is a 1-D numeric array.
At least one element survives the filter.
What a Strong Answer Covers Guidance
The boundary rule: an element equal to
cap
stays in the sample.
Removed elements leave both the sum and the count, so the mean is taken over survivors only.
A vectorized implementation and its time and space cost.
The return type, and what happens on edge inputs such as an empty result or NaN values.
Follow-up Questions Guidance
How would you handle the readout if every element could be filtered out?
When would you cap on a fixed threshold, and when on a percentile such as p99?
If the treatment itself changes how many units exceed the cap, what does filtering do to the comparison between experiment arms?