wrapping around slices in Python / numpy

后端 未结 7 2232
耶瑟儿~
耶瑟儿~ 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:22

    numpy.take in 'wrap' mode will use your indices modulo the length of the array.

    indices = range(i-2,i+3)
    neighbourhood = A.take(indices, mode='wrap')
    

    See documentation for details numpy.take

    0 讨论(0)
提交回复
热议问题