我的问题是,当我运行下面的代码时,我得到了以下令人费解的错误
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices由于函数: scipy.ndimage.interpolation.shift(input,shift,output=None,order=3,mode=‘常量’,cval=0.0,prefilter=True)
由于"https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.interpolation.shift.html#scipy-ndimage-interpolation-shift“中给出的函数的定义,这让我感到困惑。
该定义规定:
"shift :浮点或序列,可选
沿轴线的移动。如果是浮点,则shift对于每个轴都是相同的。如果是序列,则shift应为每个轴包含一个值。“
错误显式声明值应为int,而定义则显式要求浮点值。我尝试为'shift‘插入整数值,代码运行良好。我也尝试将数据移动到ndarray中,但错误仍然出现。
所以我想要做的是根据“坐标”数组中的浮点值对子像素分辨率的图像进行移位。我要么不能正确理解函数的定义,要么不能正确理解错误消息,我想知道为什么我的函数实现无法工作。
pa_float = [float(x) for x in pa_list]
dist_float =[float(x) for x in dist_list]
pa_rad_list = np.radians(pa_float)
x_coord = np.multiply(np.cos(pa_rad_list), dist_float)*(-1)*(512)
y_coord = np.multiply(np.sin(pa_rad_list), dist_float)*(512)
# The first number in x_coord and the first number in y_coord represent the first coordinate pair.... and so on for the second..n th
coords = np.column_stack((x_coord,y_coord)) # shape (72,12)
for data in glob.glob(ImageFolderPath+'/*icn.rest_avg.fits'):
scidata0 = fits.getdata(data,0)
scidata0[0,0,:,:] = ndimage.interpolation.shift(scidata0[0,0,:,:], coords[data,:], order=3,mode='nearest',prefilter=True)
finalarray.append(scidata0)发布于 2017-02-25 19:42:01
所以我找出了问题所在。'data‘参数的功能与for循环中的典型计数器不同,而是一个包含文件名的字符串。在for循环中添加一个计数器并在函数中将“data”更改为该计数器可以解决此问题。
for data in glob.glob(ImageFolderPath+'/*icn.rest_avg.fits'):
scidata0 = fits.getdata(data,0)
scidata0[0,0,:,:] = ndimage.interpolation.shift(scidata0[0,0,:,:], coords[i,:], order=3, mode='nearest', prefilter=True)
finalarray.append(scidata0)
i+=1https://stackoverflow.com/questions/42436833
复制相似问题