简体   繁体   English

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

[英]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.

相关问题 Python矩阵求解{A} [x] = [B],其中x和B的部分已知 - Python Matrix solving {A}[x] = [B] where parts of x and B are known python获取长度为X的列表,其中所有值的总和为Y - python get a list of length X where the sum of all values is Y 求解测量点列表 (x, y) 中点之间距离的函数 - Solving a function that measures distance between points in a list of points (x, y) 使用Python中的堆栈在迷宫求解算法中切换X和Y坐标 - Switching X and Y Coordinates in Maze Solving Algorithm Using Stack in Python Python - 在[x,y]列表中传递“x”“y”次 - Python - print “x” “y” times when passed in a list of [x,y] Python创建了一个X元素列表,其中的元素按Y计数。例如,如果X = 4且Y = 5,您将收到[5、10、15、20] - Python create a list of X elements where the elements count by Y. For example, if X = 4 and Y = 5 you'd receive [5, 10, 15, 20] 将 y 的实例更改为 x 中的 z(其中 x 是一个列表) - Change instance of y to z in x(where x is a list) Python列表索引,列表[[x] [y]:-z] - Python list Indexing, List[ [x][y]:-z ] Python:将列表理解列入x,y列表 - Python: List comprehension into an x,y list 有没有更优雅的方式来表达 ((x == a and y == b) 或 (x == b and y == a))? - Is there a more elegant way to express ((x == a and y == b) or (x == b and y == a))?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM