How can i store a list within a numpy 2d array?

拈花ヽ惹草 提交于 2020-01-03 00:23:09

问题


How can i store a list within a numpy 2d array?

import numpy  
A = numpy.empty([5,5], dtype=**?**)  

What should be the dtype for a variable list kind of thing here? or Is there a different way to implement this, which I strongly feel would be the case.


回答1:


I think what you want is:

>>> input = numpy.array(range(10))
>>> data = numpy.zeros((2,2), dtype=numpy.ndarray)
>>> data[1][1] = input
>>> data
    array([[0, 0],
          [0, [0 1 2 3 4 5 6 7 8 9]]], dtype=object)


来源:https://stackoverflow.com/questions/9229897/how-can-i-store-a-list-within-a-numpy-2d-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!