Problems with python super method -
i have problem: super class is:
class regressionb(object): def __init__(self, datamatrix, targets): self.x = datamatrix self.y = targets def theta_x_product(self, theta, x): homecoming self.add_column_zero(x).dot(theta) def add_column_zero(self, x): m = len(x) homecoming np.concatenate((np.ones([m,1],1]), x), axis = 1)
than, kid class:
from regressionb import * class linearregressionb(regressionb): def __init__(self, datamatrix, targets): regressionb.__init__(self, datamatrix, targets) #tryed super().__init__(datamatrix, targets) def hypothesis(self, theta): homecoming lambda x : regressionb.theta_x_product(self, theta, x) #also tryed homecoming lambda x : super().theta_x_product(theta, x)
than run console:
x = np.matrix([ [11, 12, 13, 14], [21, 22, 23, 24], [31, 32, 33, 34]]) theta = np.matrix([1, 1, 1, 1, 1]).t linearregressionb import * linear = linearregressionb(x, y) h = linear.hypothesis(theta)
for receive error:
hypothesis() takes 1 argument (2 given)
i dont see how give 2 parameters. mistake??
your kid class should like:
class linearregressionb(regressionb): def __init__(self, datamatrix, targets): super(linearregressionb, self).__init__(datamatrix, targets) def hypothesis(self, theta): homecoming lambda x : super(linearregressionb, self).theta_x_product(theta, x)
-- edit --
agreed, that, though super might not best thing since hypothesis
has not been overridden, unnecessary or not, programmer. point here imho, how phone call method parent class, , proper syntax of using super, demonstrated. not sure why i'm beingness downvoted that.
python
No comments:
Post a Comment