[英]PYTHON: solving y=a+b*x where x is a predefined list
As mentioned above, I was trying to solve the problem... description: y
is an empty list, each time the equation will be evaluated with y=a+bx
where x
is a list with no.如上所述,我试图解决这个问题...描述: y
是一个空列表,每次将用y=a+bx
评估方程,其中x
是一个没有列表的列表。 of values in it, the evaluated answer for y
will be added to the list named y
(appended).中的值, y
的评估答案将添加到名为y
(附加)的列表中。 Now my problem is that I have tried almost every google search in for this solution but no avail, I am a beginner in Python.现在我的问题是我已经尝试了几乎所有谷歌搜索来寻找这个解决方案,但无济于事,我是 Python 的初学者。
I do have the block of code which I tried according to my beginner knowledge it didn't work我确实有根据我的初学者知识尝试过的代码块,但它不起作用
ERROR_SHOWN: can't multiply sequence by non-int of type numpy.float64
hope it helps in any way...希望它以任何方式帮助...
code:代码:
y = []
for num in x:
y=a+b*x
append(y)
print(y)
hope the information I've provided is helpful希望我提供的信息有帮助
y = [a+b*num for num in x]
print(y)
I guess the following is the thing that you are trying to do.我想以下是您正在尝试做的事情。
y = []
for num in x:
some_y = a+b*num
y.append(some_y)
print(y)
Try this尝试这个
x = [1,2,3,4]
y = []
a = 1
b = 2
for num in x:
result = a+b*num
y.append(result)
print(y)
here with numpy:这里有 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.