Im 다항식에 대한 클래스를 수행하고 있는데 복사 함수에 문제가 있습니다. Poly 객체의 복사본을 생성하고 새로운 Poly 객체에 대한 참조를 반환한다고 가정합니다. 나는이 사본 아이디어에 정말로 머물렀다.파이썬에서 클래스 정의의 복사 함수
class Poly:
def __init__ (self, p):
self.a = p
self.deg= len(p) -1
if len(p) == 1 and p[0] == 0:
self.deg = -1
def evalPoly(self,x0):
''' evaluates the polynomial at value x'''
b=0
for coefficients in reversed(self.a):
b=b*x0+int(coefficients)
return b
def polyPrime(self):
'''replaces the coeffiecients of self with the coefficients
of the derivative polynomial '''
if self.deg == 0:
return np.zeroes(1,float), 0
else:
newdeg=self.deg-1
p=[i*self.a[i] for i in range(1,self.deg+1)]
p=str(p)[1: -1]
p=eval(p)
return p
def copy(self):
return Poly(self.a)
내가 새로운 폴리에 대한 참조를 폴리 객체의 복사본을 만들고 반환하는 방법에 붙어있어 어떤 도움을 주셔서 감사 문제는 실제로 __init__()
에 숨어
정확히 무슨 문제가 있습니까? – sinelaw