numpy数组追加不起作用 [英] numpy array append is not working

查看:106
本文介绍了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)

这篇关于numpy数组追加不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆