How do I get all the values from a NumPy array excluding a certain index?

前端 未结 5 2080
情书的邮戳
情书的邮戳 2020-12-05 02:14

I have a NumPy array, and I want to retrieve all the elements except a certain index. For example, consider the following array

a = [0,1,2,3,4,5,5,6,7,8,9]
<         


        
5条回答
  •  醉酒成梦
    2020-12-05 02:35

    Another solution is to use the concatenate function of NumPy:

    >>> x = np.arange(0,10)
    array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
    >>> i = 3
    >>> np.concatenate((x[:i],x[(i+1):]))
    array([0, 1, 2, 4, 5, 6, 7, 8, 9])
    

提交回复
热议问题