Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
253 B
1
Indexable
Never
def get_diagonals(matrix):
    n = matrix.shape[0]
    diagonals = []
    for i in range(n):
        diagonals.append(np.diag(matrix, i))
        diagonals.append(np.diag(matrix[:, ::-1], i))
    return [d.tolist() for d in diagonals if len(d)==n]