Scalar Multiplication of a Matrix

Easy
Machine Learning

Write a Python function that multiplies a matrix by a scalar and returns the result.

Examples

Example 1:
Input: matrix = [[1, 2], [3, 4]], scalar = 2
Output: [[2, 4], [6, 8]]
Explanation: Each element of the matrix is multiplied by the scalar.

Starter Code

def scalar_multiply(matrix: list[list[int|float]], scalar: int|float) -> list[list[int|float]]:
	return result
Lines: 1Characters: 0
Ready
The AI Interview - Master AI/ML Interviews