Object without ownership could not be modified

我写了如下代码:

defg grater_mmax(X,movingmax, threshold =0)
{
   return sum( abs(X- movingmax.last()) <=threshold )>=2
}
def  has_duplicate_max(X,window,threshold)
{
   movingmax= mmax(X,window)
   
   ret= rolling( grater_mmax{,,threshold},[X,movingmax],window  )
   
   movingmax[window-1:] = ret
   return movingmax
}
X=rand(20,40)
x = has_duplicate_max(X,20,0.1)

执行时报如下错误:

x = has_duplicate_max(X, 20, 0.1) => has_duplicate_max: movingmax[window - 1 : , : ] = ret => Object without ownership could not be modified.

但我复制一个如下所示中间变量,就不会报错:

def  has_duplicate_max(X,window,threshold)
{
   movingmax= mmax(X,window)
   Y=movingmax
   ret= rolling( grater_mmax{,,threshold},[X,movingmax],window  )
 
   Y[window-1:] = ret
   return movingmax
}

请问是什么原因

请先 登录 后评论

1 个回答

peter
 ret= rolling( grater_mmax{,,threshold},[X,movingmax],window  )

上述代码会将movingmax识别成一个元组元素,后续就不允许修改了。

请先 登录 后评论