I have an array A
of size [1, x]
of values and an array B
of size [1, y]
(y > x) of indexes corresponding to array A
. I want as result an array C
of size [1,y]
filled with values of A
.
Here is an example of inputs and outputs:
>>> A = [6, 7, 8]
>>> B = [0, 2, 0, 0, 1]
>>> C = #Some operations
>>> C
[6, 8, 6, 6, 7]
Of course I could solve it like that:
>>> C = []
>>> for val in B:
>>> C.append(A[val])
But I was actually expected a nicer way to do it. Especially because I want to use it as an argument of another function. An expression looking like A[B]
(but a working one) would be ideal. I don't mind solution using NumPy or pandas.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…