Let's say that I want to create a class, apply a method and set an attribute to the resulted object.
arr = np.array([1,2,3])
class Transformer:
def __init__(self, array):
self.array = array
def operator(self):
operator = (self.array * 2) + 60
return operator
@staticmethod
def meta(array):
meta = (max(array) + 17)
return meta
def to_operator(self):
op = self.operator()
meta = self.meta(op)
setattr(op, 'meta', meta)# or op.meta = meta
return op
t = Transformer(np.array([1, 2, 3]))
t1 = t.to_operator()
print(t1.meta())
here I get the following error:
AttributeError: 'numpy.ndarray' object has no attribute 'meta'
expected result:
>>> 83