Unpacking tuples/arrays/lists as indices for Numpy Arrays

后端 未结 4 1311
死守一世寂寞
死守一世寂寞 2020-12-01 12:22

I would love to be able to do

>>> A = numpy.array(((1,2),(3,4)))
>>> idx = (0,0)
>>> A[*idx]

and get

<         


        
4条回答
  •  臣服心动
    2020-12-01 13:06

    Try

    A[tuple(idx)]
    

    Unless you have a more complex use case that's not as simple as this example, the above should work for all arrays.

提交回复
热议问题