Python masking of 1d array -
say have 2 numpy arrays
a = [0, 2, 4, 6]
and
b = [0.03, 0.78, 0.25, 0.47, 0.98, 0.58, 0.63]
i want return 3rd array checks indices of array in b , returns value of indices in b below:
c = [0.3, 0.25, 0.98, 0.63]
i have tried
for in range(len(b)): if b[i] == a.any(): c=[i]
but 0's.
simply use
c = b[a]
this view b, if change c, change b. if don't want this, use .copy()
c = b[a].copy()
Comments
Post a Comment