I need to print (or store) all diagonals of a matrix. This includes the main diagonal ( { (i,i) | i = 1, 2, ... min(m,n) } ). Then all super and sub diagonals.For example: 1  2  3  4 5  6  7  8 9 10 11 1213 14 15 16The diagonals should be (order doesn't matter):[    [1, 6, 11, 16],    [2, 7, 12],    [5, 10, 15],    [3, 8],    [9, 14],    [4],    [13]]I believe I have a decent solution, but if there's a simpler / more efficient way to do this let me know. Input is assumed to be a list of lists as a NumPy array already has some methods to do this.def print_diags(Matrix):    m, n = len(Matrix), len(Matrix[0])    for offset in range(min(m,n)):        diag_upper = [row[i + offset]                      for i, row in enumerate(Matrix)                      if 0 <= i + offset < n]        if offset != 0:            diag_lower = [row[i - offset]                      for i, row in enumerate(matrix)                      if 0 <= i - offset < m]            print(diag_upper, diag_lower)        else:            print(diag_upper)
Print matrix diagonals method
python;python 3.x;matrix