wrapping around slices in Python / numpy

后端 未结 7 2260
耶瑟儿~
耶瑟儿~ 2020-12-05 17:41

I have a numpy array, and I want to get the \"neighbourhood\" of the i\'th point. Usually the arrays I\'m using are two-dimensional, but the following 1D example illustrates

7条回答
  •  不知归路
    2020-12-05 18:20

    you can use argument axis=0 of numpy.take for n-d array.

    A = zip(range(0,101,10),range(0,11)) #create 2-d list
    A = numpy.array(A)   #create 2-d array  
    indices = range(i-2,i+3)
    neightbourhood = A.take(indices,axis=0,mode='wrap')
    

    The same axis=0 will work for n*m dimensions...

提交回复
热议问题