【发布时间】:2012-09-04 04:48:24
【问题描述】:
早安专家,
我有一个包含整数的数组,我有一个列表,其中包含按特殊顺序排序的数组中的唯一值。我想要的是创建另一个数组,该数组将包含 a 数组中每个值的索引。
#a numpy array with integer values
#size_x and size_y: array dimensions of a
#index_list contain the unique values of a sorted in a special order.
#b New array with the index values
for i in xrange(0,size_x):
for j in xrange(0,size_y):
b[i][j]=index_list.index(a[i][j])
这可行,但需要很长时间才能完成。有更快的方法吗?
非常感谢您的帮助
德语
【问题讨论】:
-
使用 numpy 排序、精美的索引或任何你需要的东西。 (或者例如 np.unique 及其可选返回)它应该比基于字典的方法快得多。
标签: python arrays list numpy indexing