简体   繁体   中英

How do I take an array indicating the indicies of another array and store those values in yet another array?

I am using Python 3.6 in Jupyter Notebooks.

So, I have an array that indicates the indices of another array, for example,

[10, 123, 320, 800] 

would correspond to entry 10, entry 123, and so on. These are the indices of value of interest in another array, around 700 entries long. I need to take these indicated entries and store them in a separate array. I also need to keep all the entries in the same chronological order they were in before I started. Any ideas?

假设索引列表存储为变量i ,主列表存储为变量l ,则可以使用以下列表推导构造一个列表,该列表的值与i的索引指示的l的值相对应:

[l[n] for n in i]

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