The code repeats calculating the returned lists x, y, z from class (XYZ) for each round inside the (S) class loop, and that is time consuming. How could I get those lists out of the loop? EXPLAINING: to get S you need W and to get W you need to get x, y, z from XYZ (but x, y, z lists are constant value, and no need to recalculate them each round of S) Here is the code:
class XYZ('there is some other classes here'): def __init__(self): super().__init__() def get_x_y_z(self): x = [] y = [] z = [] ##some input values and used the inherited class## return x,y,z class W(XYZ): def __init__(self): def get_w(self): x_y_z = XYZ.get_x_y_z(self) x = x_y_z[0] y = x_y_z[1] z = x_y_z[2] # w = f(x,y,z)+..., but here is a brief formula w = x*y*z return w class S(W): def __init__(self): def get_s(self): s = [] n=1000 w = W.get_w(self) for i in range(n): # s = f(w)+...., but here is a brief formula v = w+i s.append(v) return s https://stackoverflow.com/questions/65589251/excluding-repeated-calculating-the-results-of-return-value-from-class-inside-loo January 06, 2021 at 10:10AM
没有评论:
发表评论