나는 새로운 OOP입니다. 다음 클래스와 메서드를 작성했으며 다른 메서드 내부에서 메서드를 호출하고 싶습니다. 그러나 이름 다항식 (방법)이 정의되지 않았다는 오류가 발생합니다. 이유는 무엇입니까?
#Imports
import numpy as np
from scipy.signal import argrelextrema
from scipy import optimize
class MaxImpact():
def __init__(self,X,Y):
self.X = X
self.Y = Y
self.minima_index = argrelextrema(self.Y,np.less)
self.maxima_index = argrelextrema(self.Y,np.greater)
self.approx_converge_pt = []
self.approx_converge_idx = []
# .... (bunch of other methods)
def calc_convergePt_X(self):
for i in range(1,len(self.Y)):
if (self.Y[i-1] < 0 and self.Y[i] > 0) or (self.Y[i-1] > 0 and self.Y[i] < 0):
self.approx_converge_idx.append(i-1)
for i in self.approx_converge_idx:
self.x_val = self.X[i]
return(self.x_val)
def polynomial(self):
func = clf4.intercept_[0] + clf4.coef_[0][1] * self.X + clf4.coef_[0][2]*np.power(self.X,2) + clf4.coef_[0][3]*np.power(self.X,3) + clf4.coef_[0][4]*np.power(self.X,4)
def neutral_state(self):
sol = optimize.root(polynomial(),self.x_val)
maxImp2 = MaxImpact(XX,YY4)
print(maxImp2.calc_convergePt_X())
print(maxImp2.neutral_state())
여기서는 중립 상태 메서드 내에 다항식 eq를 포함하는 다항식 메서드를 호출하고 싶습니다. "이름 다항식이 정의되지 않았습니다"라는 오류가 발생합니다.
인스턴스에서 메서드를 호출해야합니다. 동일한 인스턴스에서 메서드를 호출하려면를 사용 self
하여 참조하십시오.
def neutral_state(self):
sol = optimize.root(self.polynomial(), self.x_val)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다