Fill Missing
A broken sensor wrote -1 whenever it failed to measure. Return a new array in which every -1 is replaced by the average of the readings that are not -1. At least one reading is valid.
Example 1
readings [4,-1,8]
returns [4.0,6.0,8.0]
The valid readings average (4 + 8) / 2 = 6, so the result is [4, 6, 8].
Constraints
1 <= len(readings) <= 100- Valid readings are 0 or more, and at least one reading is not -1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- First Day Over LimitEasy
- Full ColumnsEasy
- Good ColumnsEasy
- Group MaximumsEasy
- Is SortedEasy
- Is SymmetricEasy
- Largest GapEasy
- Latest PeakEasy