How do I make a grid of empty lists in numpy that 'accepts' appending?

后端 未结 3 949
南笙
南笙 2021-01-24 16:09

I am trying to use numpy.append but something goes wrong and it just doesn\'t make sence to me anymore. Can someone explain why I am getting an error?

>>&g         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-24 16:41

    I know this is a rather unusual use case but in fact it can be very handy to have an ndarray holding lists in each cell. Imho numpy should allow to pass a lambda function to the fill mehtod. But to achive what you want this is what I do:

    m = np.empty((12, 12), dtype=object)
    for i in np.ndindex(m.shape): m[i] = []
    

提交回复
热议问题