PYTHON:求解y=a+b*x,其中x是预定义列表



如上所述,我试图解决这个问题。。。description:y是一个空列表,每次用y=a+bx对等式进行求值时,其中x是一个没有值的列表,y的求值答案将添加到名为y的列表中(附加(。现在我的问题是,我几乎在谷歌上搜索过这个解决方案,但都无济于事,我是Python的初学者。

我确实有一块代码,根据我的初学者知识,我尝试过它不起作用

ERROR_SHOWN: can't multiply sequence by non-int of type numpy.float64

希望它在任何方面都有帮助。。。

代码:

y = []
for num in x:
y=a+b*x
append(y)
print(y)

希望我提供的信息对有帮助

y = [a+b*num for num in x]
print(y)

我想下面是您要做的事情。

y = []
for num in x:
some_y = a+b*num
y.append(some_y)
print(y)

试试这个

x = [1,2,3,4]
y = []
a = 1
b = 2
for num in x:
result = a+b*num
y.append(result)
print(y)

此处带有numpy:

import numpy as np
x = np.array([1,2,3,4,5,6,7,8,9,10])
a, b= 10,5
y = a+b*x
y

最新更新