getting the opposite diagonal of a numpy array

后端 未结 3 1730
天命终不由人
天命终不由人 2020-12-30 19:26

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

3条回答
  •  情歌与酒
    2020-12-30 20:17

    Here are two ideas:

    step = len(array) - 1
    
    # This will make a copy
    array.flat[step:-step:step]
    
    # This will make a veiw
    array.ravel()[step:-step:step]
    

提交回复
热议问题