根据第一个数组选择第二个数组

时间:2015-11-25 14:37:44

标签: python arrays numpy conditional-statements subset

我们说我有两个 len(1000)

的阵列
array_a = np.array([1,2,3,....,1000]) # length of 1000
array_b = np.array([32344,83242,94323,....,48984]) # length of 1000

现在我根据特定条件选择array_a的子集:

subset_a = array_a[(array_a>10) * (array_a<500)]

现在,如何选择属于上述array_b的{​​{1}}的值?

我试过

subset_a

但是我收到了错误

subset_b = array_b[subset_a]

1 个答案:

答案 0 :(得分:2)

你在找这个吗?

import numpy as np

array_a = np.array([1,2,3,4,5]) # length of 5
array_b = np.array([6,7,8,9,10]) # length of 5

condition = array_a>3
print condition
subset_a = array_a[condition]
print subset_a
subset_b = array_b[condition]
print subset_b

http://ideone.com/dAFLYL