将元素追加到numpy nd数组

 收藏

我已经初始化了一个numpy nd数组,如下所示

arr =  np.zeros((6, 6))

该空数组作为输入参数传递给函数,

def fun(arr):
    arr.append(1) # this works for arr = [] initialization
    return arr

for  i in range(0,12):
     fun(arr) 

But append doesn't work for nd array. I want to fill up the elements of the nd array row-wise. Is there any way to use a python scalar index for the nd array? I could increment this index every time fun is called and append elements to arr

有什么建议么?

回复