可以将插值值乘以乘以,显示非类型
我有一个书面插值功能。但是当我调用该功能时,它可以完美地工作。但是,当获得的值乘以时,它显示了类型: *:'nontype'和scipy.intpaly intpely
interp1d Interp1d
def repair(hour):
x = [300,600,900,1200,1500,1800,2100,2400,2700,3000,3300,3600,3900,4200,4500,4800,5100,5400,5700,6000]
y = [0,1,2,4,6,9,12,16,20,25,30,36,42,49,56,64,72,81,90,100]
x_interip = interp1d(x,y)
r = x_interip(hour)
print(r)
p = repair(400)
c = p*100
print(c)
这是我的代码,我不知道在哪里错。我是基本的学习者。
I have a written a interpolation function. but when I called the function, it works perfectly. but when the obtained value is multiplied, it shows TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
from scipy.interpolate import interp1d
def repair(hour):
x = [300,600,900,1200,1500,1800,2100,2400,2700,3000,3300,3600,3900,4200,4500,4800,5100,5400,5700,6000]
y = [0,1,2,4,6,9,12,16,20,25,30,36,42,49,56,64,72,81,90,100]
x_interip = interp1d(x,y)
r = x_interip(hour)
print(r)
p = repair(400)
c = p*100
print(c)
this is my code, I dont know where is wrong. I am a basic learner.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出现错误是因为您的函数没有返回任何内容。将
return r
添加到函数末尾。否则,p
的值将为None
,并且错误是由乘以p
产生的(即None
,因此类型为NoneType
) 到 100(int
类型)。The error arises because your function does not return anything. Add
return r
to the end of the function. Otherwise, the value ofp
will beNone
and the error arises from multiplyingp
(which isNone
, hence the type isNoneType
) to 100 (int
type).