1

我正在尝试切片,但出现以下错误消息:slice indices must be integers or None or have an __index__ method

descriptors = numpy.fft.fftshift(descriptors)
center_index = len(descriptors) / 2
descriptors = descriptors[center_index - degree / 2:center_index + degree / 2]
4

1 回答 1

2

在 python3 中,您需要使用//与 python2 不同的地板除法/

import numpy as np

descriptors = [ 0.,  1.,  2.,  3.,  4., -5., -4., -3., -2., -1.]
descriptors = np.fft.fftshift(descriptors)
print(descriptors)
center_index = len(descriptors) // 2
degree = 4
descriptors = descriptors[center_index - degree // 2 : center_index + degree // 2]
print(descriptors)

输出:

[-5. -4. -3. -2. -1.  0.  1.  2.  3.  4.]
[-2. -1.  0.  1.]
于 2019-07-03T21:37:37.237 回答