开发者

List of tuples to Numpy recarray

Given a list of tuples, where each t开发者_如何学Gouple represents a row in a table, e.g.

tab = [('a',1),('b',2)]

Is there an easy way to convert this to a record array? I tried

np.recarray(tab,dtype=[('name',str),('value',int)])

which doesn't seem to work.


try

np.rec.fromrecords(tab)

rec.array([('a', 1), ('b', 2)], 
          dtype=[('f0', '|S1'), ('f1', '<i4')])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜