Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-141

Matrix Negative

Problem

Return the additive inverse of matrix A: every entry is negated.

B[i][j] = -A[i][j], so A + B is the zero matrix.

Hint

Negate each entry; the shape stays the same.

Test cases

case 1
in: [[[1,-2],[3,4]]]
expected: [[-1,2],[-3,-4]]
case 2
in: [[[0,0]]]
expected: [[0,0]]
case 3
in: [[[1.5,-2.5]]]
expected: [[-1.5,2.5]]
case 4
in: [[[0]]]
expected: [[0]]
Starter codePython
def negate_matrix(A):
    # Your code here
    pass

4 test cases · run your code against them in the editor