Python 是否可以在guvectorize函数中返回输出数组形状未知的数组
我想知道如果我不知道数组的大小,如何使用numba guvectorize函数返回数组。 我基本上有一个函数,它接收一个向量,我返回一个数组,在这个数组中,它的大小将在函数中改变。我的问题是我不能预先设置返回数组的形状 例如:Python 是否可以在guvectorize函数中返回输出数组形状未知的数组,python,arrays,numpy,numba,Python,Arrays,Numpy,Numba,我想知道如果我不知道数组的大小,如何使用numba guvectorize函数返回数组。 我基本上有一个函数,它接收一个向量,我返回一个数组,在这个数组中,它的大小将在函数中改变。我的问题是我不能预先设置返回数组的形状 例如: @guvectorize ([(float64[:],int64[:,:])], '(n),()->(n,2)') def mysegmentation(Thresholding,StimSegments_time): count = 0 for i
@guvectorize ([(float64[:],int64[:,:])], '(n),()->(n,2)')
def mysegmentation(Thresholding,StimSegments_time):
count = 0
for i in range(Thresholding.shape[0]-1):
if Thresholding[i]==0. and Thresholding[i+1]==1.:
StimSegments_time[count,0] = i
elif Thresholding[i]==1. and Thresholding[i+1]==0.:
StimSegments_time[count,1] = i
count += 1
阈值可以有,比如说(1000)个元素,时间可以有(5,2)或(7,2)或其他(x,2)我也有同样的问题。但是我所能帮助的是,您不能在decorator中添加一个固定的数字(即->(n,2)是不正确的) 对于该问题,人们建议在输入中添加伪数组参数,并在输出中使用其长度,如下所述: