Average of Chosen Rows
Take only the rows of grid whose row numbers are listed in chosen (in that order, and a row number may repeat), then return a list with the average of each column over those rows. Hint: grid[chosen] picks rows.
Example 1
grid [[1,2],[3,4],[5,6]]
chosen [0,2]
returns [3.0,4.0]
Rows 0 and 2 are [1, 2] and [5, 6], averaging [3.0, 4.0].
Constraints
1 <= rows, columns <= 10chosenhas at least one valid row number
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Average of Top ThreeEasy
- Biggest JumpEasy
- Brighten ImageEasy
- Bucket CountsEasy
- Busiest ColumnEasy
- Change Between RowsEasy
- Close EnoughEasy
- Closest to OriginEasy