[英]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. 我在Jupyter Notebook中使用Python 3.6。
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. 对应于条目10,条目123,依此类推。 These are the indices of value of interest in another array, around 700 entries long.
这些是另一个数组中感兴趣的价值指数,大约700个条目。 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.