Mockbit/#67
ML CodingeasyNumpy~10m

The Aggregator

Problem

You are building a data pipeline that processes feature matrices from multiple sensors. Each row represents one sensor reading across different features, and each column represents one feature across all readings. Your downstream model needs both row-level and column-level aggregations.

Given a 2D matrix, return a list of two lists:

  • First list: sum of each row (one value per row)
  • Second list: sum of each column (one value per column)
Examples

Example 1

Input: [[1, 2, 3], [4, 5, 6]]
Output: [[6, 15], [5, 7, 9]]

Row sums: [1+2+3, 4+5+6] = [6, 15]. Col sums: [1+4, 2+5, 3+6] = [5, 7, 9]. axis=1 for rows, axis=0 for columns.

Example 2

Input: [[10], [20], [30]]
Output: [[10, 20, 30], [60]]

Single column matrix. Row sums: [10, 20, 30]. Col sum: [60].

Example 3

Input: [[-1, -2], [-3, -4]]
Output: [[-3, -7], [-4, -6]]

All negatives. Row sums: [-1+(-2), -3+(-4)] = [-3, -7]. Col sums: [-1+(-3), -2+(-4)] = [-4, -6].

Constraints
  • 1 <= rows <= 100
  • 1 <= cols <= 100
  • -1000 <= matrix[i][j] <= 1000
Reference solution

Reference solution available after you attempt the question.

Ready to solve it?

Start a session on Mockbit #67. Write your code, run it against hidden tests, and get graded with specific critique on each axis.

Related ML Coding questions
← Back homemockbit.io/q/67
PrivacyTerms© 2026 Mockbit