So in numpy arrays there is the built in function for getting the diagonal indices, but I can\'t seem to figure out how to get the diagonal starting from the top right rathe
There is
In [47]: np.diag(np.fliplr(array))
Out[47]: array([ 4, 8, 12, 16, 20])
or
In [48]: np.diag(np.rot90(array))
Out[48]: array([ 4, 8, 12, 16, 20])
Of the two, np.diag(np.fliplr(array))
is faster:
In [50]: %timeit np.diag(np.fliplr(array))
100000 loops, best of 3: 4.29 us per loop
In [51]: %timeit np.diag(np.rot90(array))
100000 loops, best of 3: 6.09 us per loop