Sub matrix of a list of lists (without numpy)

前端 未结 4 1367
误落风尘
误落风尘 2020-12-09 12:04

Suppose I have a matrix composed of a list of lists like so:

>>> LoL=[list(range(10)) for i in range(10)]
>>> LoL
[[0, 1, 2, 3, 4, 5, 6, 7,         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 12:50

    I dont know if its easier, but let me throw an idea to the table:

    from itertools import product
    r = (1+1, 4+1)
    s = (2+1, 5+1)
    array = [LoL[i][j] for i,j in product(range(*r), range(*s))]
    

    This is a flattened version of the submatrix you want.

提交回复
热议问题