首页 > 解决方案 > 当它不属于函数范围时如何使用:arg?

问题描述

我正在尝试使用以下函数,其中:arg显然不属于函数范围。

class Transformer(object):

def __init__(self, mu, norm):

    self.mu = mu
    self.norm = norm

def Normalise(self, data):
    """
    Perform the normalisation (data-mu)/norm.
    --------------------------------------
    :arg
    data: data that needs to be transformed
    mu: scale
    norm: normlisation constant
    :return
    The normalized data
    """     
    return (data-self.mu)/self.norm

当我插入该data值时,它告诉我mu未定义。但是,如果我mu之前定义调用该函数,它就不起作用。我不确定如何:arg在这种情况下使用。

标签: pythonarguments

解决方案


像这样的东西:

tr = Transformer(mu=somevalue, norm=somevalue)
normalized = tr.Normalise(somevariable)

print(normalized)

推荐阅读