Access multiple elements of an array

后端 未结 3 2136
心在旅途
心在旅途 2020-12-06 15:08

Is there a way to get array elements in one operation for known rows and columns of those elements? In each row I would like to access elements from col_start to col_end (ea

3条回答
  •  暖寄归人
    2020-12-06 15:29

    I think you're looking for something like the below. I'm not sure what you want to do with them when you access them though.

    indexes = [(4,6), (0,2), (2,4), (8, 10)]
    arr = [
        [ . . . . | | | . . . . . ],
        [ | | | . . . . . . . . . ],
        [ . . | | | . . . . . . . ],
        [ . . . . . . . . | | | . ]
    ]
    
    for x in zip(indexes, arr):
        index = x[0]
        row = x[1]
        print row[index[0]:index[1]+1]
    

提交回复
热议问题