Converting list of lists to numpy array with multiple data types

后端 未结 2 499
傲寒
傲寒 2021-01-16 10:19

I have a list of lists I\'ve read from a file. Each of the inner lists is six elements in length, and has 3 strings and 5 floats. How do I convert this list of lists into

2条回答
  •  独厮守ぢ
    2021-01-16 11:02

    I had the same problem, but tuples are no solution. So I found (python 3.7.1):

    ll = [['one','two',1,1.23],['four','five',4,34.3],['six','seven',4,34.3]]
    
    np.array(ll, dtype = 'object')
    

    result:

    array([['one', 'two', 1, 1.23],
       ['four', 'five', 4, 34.3],
       ['six', 'seven', 4, 34.3]], dtype=object)
    

提交回复
热议问题