Back to Practice
#0099

Scale Rows With Multipliers

MediumNumPy25 min20 XP

Problem

Given matrix shape (rows, cols) and multipliers shape (rows,), return a matrix where each row is multiplied by its corresponding multiplier.

Why This Matters

Row-wise broadcasting is a common source of shape confusion. This problem makes the required reshape explicit.

Function Signature

def scale_rows(matrix, multipliers):

Examples

Example 1
Input[[1,2],[3,4]], [10,100]
Output[[10,20],[300,400]]

The first row is multiplied by 10 and second row by 100.

Constraints

  • Return the exact structure requested.
  • Handle the edge cases mentioned in the prompt.
  • Prefer clear logic over clever one-liners.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[[1,2],[3,4]], [10,100]
Expected[[10,20],[300,400]]

The first row is multiplied by 10 and second row by 100.

Hidden Test Categories
one rownegative multiplierfloat matrix