python - 当它不属于函数范围时如何使用: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
在这种情况下使用。
解决方案
像这样的东西:
tr = Transformer(mu=somevalue, norm=somevalue)
normalized = tr.Normalise(somevariable)
print(normalized)
推荐阅读
- python - 如何使用 Flask 和 HTML 创建可变数量的链接?
- php - 从一长串 LCID 中创建一个数组
- php - 将 Zoom 与 Codeigniter (curl) 连接起来
- reactjs - React Native 如何使用 Jest 测试动画
- angular - 只允许选中一个复选框并获取选中的值
- javascript - 如何在不加载 js 的情况下获得音频的持续时间
- react-native - React Native,Native Modules 返回空对象 - {}
- javascript - 如何使用 querySelector 查找具有给定属性的多个可能值的元素?
- php - Wordpress 中的多个帖子循环
- java - Mockito 单元测试:参数匹配器的无效使用