numpy数组追加不起作用

问题描述:

我正在尝试在numpy数组中追加.它没有显示任何错误,但没有在数组中追加值.我不明白是什么原因.

i am trying to append in numpy array.it does not showing any error but not appending the values in the array. i can't understand what's the reason.

ind=[]
ind=np.array(ind)
ind

out:array([], dtype=float64)
rand_num
out:0.2581020651429914

for i in T_Yk:
    print i,rand_num,i>=rand_num
    if i>=rand_num:
        np.append(ind,i)


0.841407208505 0.258102065143 True
0.544017164891 0.258102065143 True
0.847014100035 0.258102065143 True
0.837888398913 0.258102065143 True
0.602345432651 0.258102065143 True
0.758088894007 0.258102065143 True
0.875552313712 0.258102065143 True
0.566129640396 0.258102065143 True
0.398095901072 0.258102065143 True
0.708554596955 0.258102065143 True
0.308165627166 0.258102065143 True
0.716732072072 0.258102065143 True
0.760848001298 0.258102065143 True
0.307696603977 0.258102065143 True
0.574524448748 0.258102065143 True
0.608537650411 0.258102065143 True
0.661614576393 0.258102065143 True
0.358783413082 0.258102065143 True
0.396823316883 0.258102065143 True
0.867563492221 0.258102065143 True
0.520237352281 0.258102065143 True
0.866000916749 0.258102065143 True
0.851035162881 0.258102065143 True
0.566755675099 0.258102065143 True
0.687814928058 0.258102065143 True
0.787882814547 0.258102065143 True
0.8790451058 0.258102065143 True
0.538294379248 0.258102065143 True
0.543694673875 0.258102065143 True

但是当我打印数组ind时,它会显示

but when i print the array ind,it shows

array([], dtype=float64)

np.appendlist.append不同,不是 就地操作.

np.append, unlike list.append, is not an in-place operation.

因此,请分配回原始指针:

Therefore, assign back to original pointer:

ind = np.append(ind, i)