numpy shorthand for taking jagged slice

前端 未结 3 425
萌比男神i
萌比男神i 2020-12-21 02:22

I have an operation that I\'m doing commonly which I\'m calling a \"jagged-slice\" because I don\'t know the real name for it. It\'s best explained by example:



        
3条回答
  •  一个人的身影
    2020-12-21 03:13

    The elements in jagged_slice_of_a are the diagonal elements of a[:,entries_of_interest]

    A slightly less cumbersome way of doing this would therefore be to use np.diagonal to extract them.

    jagged_slice_of_a = a[:, entries_of_interest].diagonal()
    

提交回复
热议问题