MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / scalar_multiply

Function scalar_multiply

matrix/matrix_operation.py:50–57  ·  view source on GitHub ↗

>>> scalar_multiply([[1,2],[3,4]],5) [[5, 10], [15, 20]] >>> scalar_multiply([[1.4,2.3],[3,4]],5) [[7.0, 11.5], [15, 20]]

(matrix: list[list[int]], n: float)

Source from the content-addressed store, hash-verified

48
49
50def scalar_multiply(matrix: list[list[int]], n: float) -> list[list[float]]:
51 """
52 >>> scalar_multiply([[1,2],[3,4]],5)
53 [[5, 10], [15, 20]]
54 >>> scalar_multiply([[1.4,2.3],[3,4]],5)
55 [[7.0, 11.5], [15, 20]]
56 """
57 return [[x * n for x in row] for row in matrix]
58
59
60def multiply(matrix_a: list[list[int]], matrix_b: list[list[int]]) -> list[list[int]]:

Callers 1

inverseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected