Reference an Element in a List of Tuples

后端 未结 7 417
无人共我
无人共我 2020-12-08 10:37

Sorry in advance, but I\'m new to Python. I have a list of tuples, and I was wondering how I can reference, say, the first element of each tuple w

7条回答
  •  一向
    一向 (楼主)
    2020-12-08 10:56

    So you have "a list of tuples", let me assume that you are manipulating some 2-dimension matrix, and, in this case, one convenient interface to accomplish what you need is the one numpy provides.

    Say you have an array arr = numpy.array([[1, 2], [3, 4], [5, 6]]), you can use arr[:, 0] to get a new array of all the first elements in each "tuple".

提交回复
热议问题