Reputation: 97
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
but when i print the array ind,it shows
array([], dtype=float64)
Upvotes: 1
Views: 5427
Reputation: 2025
np.append
, unlike list.append
, is not an in-place operation.
Therefore, assign back to original pointer:
ind = np.append(ind, i)
Upvotes: 7