Replace values in array of indexes corresponding to another array

后端 未结 6 1685
Happy的楠姐
Happy的楠姐 2020-12-20 03:22

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

6条回答
  •  粉色の甜心
    2020-12-20 04:01

    Once you're using numpy.array you're able to do exactly what you want with syntax you expect:

    >>> a = array([6, 7, 8])
    >>> b = array([0, 2, 0, 0, 1])
    >>> a[b]
    array([6, 8, 6, 6, 7])
    

提交回复
热议问题