简体   繁体   English

如何获取一个指示另一个数组的索引的数组,并将这些值存储在另一个数组中?

[英]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.

相关问题 如何将值从一个数组存储到另一个数组? - How can i store values from one array to another array? 如何用在另一个数组中找到的值的索引替换 Python NumPy 数组中的值? - How can I replace values in a Python NumPy array with the index of those values found in another array? 如何检查熊猫中另一个数组中存在的数组中值的百分比? - How do I check the % of values in an array that exist in another array in pandas? 有没有更优雅的方法来按2D数组中的索引取值? - Is there a more elegant way to take values by indicies in 2D array? 如何将整个阵列存储到另一个阵列中 - How do you store an entire array into another array 获取索引数组,在另一个数组中查找匹配的索引并替换值 - Take array of indices, find matching indices in another array and replace values 基于另一个数组从 numpy 数组的行和列中取值 - Take values from row and column of numpy array based on another array 当我从另一个文件导入数组时,我是只从其中获取数据还是需要使用原始文件构建它的方式“构建”数组? - When I import an array from another file, do I take just the data from it or need to “build” the array with how the original file build it? 如何将 numpy 数组舍入到另一个数组中定义的最接近的值? - How do I round a numpy array to its closest values defined in another array? 如何根据另一个数组的元素复制数组的元素? - How do I copy elements of an array based on elements of another array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM