Unsuccessful append to an empty NumPy array

前端 未结 6 1608
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 14:05

I am trying to fill an empty(not np.empty!) array with values using append but I am gettin error:

My code is as follows:

import numpy as np
result=np         


        
6条回答
  •  佛祖请我去吃肉
    2020-12-23 14:50

    This error arise from the fact that you are trying to define an object of shape (0,) as an object of shape (2,). If you append what you want without forcing it to be equal to result[0] there is no any issue:

    b = np.append([result[0]], [1,2])
    

    But when you define result[0] = b you are equating objects of different shapes, and you can not do this. What are you trying to do?

提交回复
热议问题