'how do I solve an assertion error with scalar multiplication

I'm writing a code to multiply an array by one single number. I can get the results right but I can't get it past the assertion. Is there an easy way to figure out assertion errors? I've read that adding print helps visualize the result, which is correct, so I'm stuck here trying to figure out what I did wrong. Any ideas?

Code:

def matrix_scale(matrix, x):
    # copy matrix to keep original
    new_matrix = matrix.copy()
    out_matrix = np.multiply(new_matrix,x)
    return out_matrix


my_matrix = [[1, 0, 0],
            [0, 1, 0],
            [0, 0, 1]]

double = matrix_scale(my_matrix, 2) print(double) # included here to see the result negation = matrix_scale(my_matrix, -1) print(negation) # included here to see the result

assert(double == [[2, 0, 0], [0, 2, 0], [0, 0, 2]])
assert(negation == [[-1, 0, 0], [0, -1, 0], [0, 0, -1]])

This is the error message I get:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Process finished with exit code 1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source