我在一个数组和一个矩阵上测试了这个函数;它给出了关于切片索引的相同类型错误。所以我的指标实际上是一个整数。你知道吗
def getpar(PSI):
n = PSI.shape[0]
x = n//2+1
gamma = PSI[0:x]
c = PSI[(x + 1):n]
return gamma,c
getpar(np.matrix([[1,2,3],[1,2,3],[2,4,5],[2,5,2]]))
看来x的计算是个问题。你知道吗
> Traceback (most recent call last):
File "C:\Users\Azerty\PycharmProjects\toto\venv37\lib\site-packages\IPython\core\interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-20-f29d42dbbc56>", line 1, in <module>
getpar(np.matrix([[1,2,3],[1,2,3],[2,4,5],[2,5,2]]))
File "C:/Users/Azerty/PycharmProjects/toto/venv37/HARST/HARST.py", line 12, in getpar
x = itn//2+1
File "C:\Users\Azerty\PycharmProjects\toto\venv37\lib\site-packages\numpy\matrixlib\defmatrix.py", line 195, in __getitem__
out = N.ndarray.__getitem__(self, index)
TypeError: slice indices must be integers or None or have an __index__ method
您的问题是您正在使用一个float来索引数组。numpy float不能使用
//
转换为int。所以你可以这样做:你也可以
print(x, type(x))
,你会看到它是什么。你知道吗相关问题 更多 >
编程相关推荐