Convert numpy array to tuple

后端 未结 5 1676
北海茫月
北海茫月 2020-12-07 11:12

Note: This is asking for the reverse of the usual tuple-to-array conversion.

I have to pass an argument to a (wrapped c++) function as a nested tupl

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 11:34

    I was not satisfied, so I finally used this:

    >>> a=numpy.array([[1,2,3],[4,5,6]])
    >>> a
    array([[1, 2, 3],
           [4, 5, 6]])
    
    >>> tuple(a.reshape(1, -1)[0])
    (1, 2, 3, 4, 5, 6)
    

    I don't know if it's quicker, but it looks more effective ;)

提交回复
热议问题