Traverse Matrix in Diagonal strips

前端 未结 16 1860
暖寄归人
暖寄归人 2020-11-28 02:55

I thought this problem had a trivial solution, couple of for loops and some fancy counters, but apparently it is rather more complicated.

So my question is, how woul

16条回答
  •  臣服心动
    2020-11-28 03:32

    Just in case somebody needs to do this in python, it is very easy using numpy:

    #M is a square numpy array    
    for i in range(-M.shape[0]+1, M.shape[0]):
        print M.diagonal(offset=i)
    

提交回复
热议问题