简体   繁体   中英

How to iterate over a list and append all the results to an array

I want to extract the values from "all", for which the first columns is 0 or 1.

arr = np.zeros((0,2))
for num in [0,1]:
    spike = np.vstack((arr, all[all[:,0] == num] ))
print(spike)

When i print "spike" only the values of 1 are present.

您在循环中覆盖了spike的值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM