Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-163

Symmetric Part

Problem

Compute the symmetric part of a square matrix A:

sym(A) = (A + A^T) / 2

The result is always symmetric.

Hint

The diagonal entries are unchanged; off-diagonal pairs are averaged.

Test cases

case 1
in: [[[1,2],[3,4]]]
expected: [[1,2.5],[2.5,4]]
case 2
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 3
in: [[[1,2,3],[4,5,6],[7,8,9]]]
expected: [[1,3,5],[3,5,7],[5,7,9]]
case 4
in: [[[0,0],[0,0]]]
expected: [[0,0],[0,0]]
Starter codePython
def symmetric_part(A):
    # Your code here
    pass

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