Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
'&燃气轮机=';在';发电机&x27;和';int';Python错误_Python - Fatal编程技术网

'&燃气轮机=';在';发电机&x27;和';int';Python错误

'&燃气轮机=';在';发电机&x27;和';int';Python错误,python,Python,y是有待确定的变量 我试着做一个这样的循环: t = [1,2] J = range(5) 但当我尝试将其作为一个循环时:例如,像这样 1*x + y[0,0] >= 10 1*x + y[0,1] >= 10 1*x + y[0,2] >= 10 1*x + y[0,3] >= 10 1*x + y[0,4] >= 10 2*x + y[1,0] >= 10 2*x + y[1,1] >= 10 2*x + y[1,2] >= 10 2*x

y是有待确定的变量 我试着做一个这样的循环:

t = [1,2]
J = range(5)
但当我尝试将其作为一个循环时:例如,像这样

1*x + y[0,0] >= 10
1*x + y[0,1] >= 10
1*x + y[0,2] >= 10
1*x + y[0,3] >= 10
1*x + y[0,4] >= 10

2*x + y[1,0] >= 10
2*x + y[1,1] >= 10
2*x + y[1,2] >= 10
2*x + y[1,3] >= 10
2*x + y[1,4] >= 10
这样说我就错了

for i in range(t):
    (t[i]*x + y[i,j] for j in J) >= 10

我想知道为什么我会犯这个错误。当我为每个t键入索引,为y键入循环索引时,它不会给我任何错误,但当我循环它时,它会给我一个错误。我做错了什么?

很难说出你在问什么。我认为您需要一个布尔值列表,显示原始列表中每个项的计算是否大于或等于10。如果是这样,您需要在循环中对每个项目进行比较,而不是对整个循环进行比较。也许:

'>=' not supported between instances of 'generator' and 'int'

但是,我看不出你在用发电机做什么,所以我不确定这是否有用。

很难说你在问什么。我认为您需要一个布尔值列表,显示原始列表中每个项的计算是否大于或等于10。如果是这样,您需要在循环中对每个项目进行比较,而不是对整个循环进行比较。也许:

'>=' not supported between instances of 'generator' and 'int'

然而,我看不出你用这个发电机到底在做什么,所以我不确定这是否会有帮助。

你可能想要这样的东西

(t[i]*x + y[i,j] >= 10 for j in J)

这将为您提供一个包含10个
True
s和/或
False
s的列表,命名为
models

您可能需要类似

(t[i]*x + y[i,j] >= 10 for j in J)

这将为您提供10个
True
s和/或
False
s的列表,命名为
models

不要使用for循环,使用NUMPY

(t[i]*x+y[i,j]代表j中的j)
是一个。你也没有做任何比较,你只是把它扔进了真空

但请注意,这是
numpy
(我假设,因为您正在执行
y[I,j]
)。如果您使用
for
循环,则可能是做错了什么。取而代之的是按设计使用numpy。。。使用数组操作

T = [1,2]
J = range(5)
models = [(t*x) + y[i,j] >= 10 for j in J for i, t in enumerate(T)]
ta da全新的布尔数组。以下是一个例子:

t = np.arange(2)[:, np.newaxis]
comparison = (t*x + y) >= 10
哪个输出

import numpy as np

x = 1.5
y = np.random.randint(0, 16, (2, 5))
t = np.arange(2)[:, np.newaxis]

new = t*x + y
comparison = new >= 10

print(f'x = {x},\ny = \n{y},\n\nt = \n{t},\n\nnew = \n{new},\n\ncomp = \n{comparison}')

不要使用for循环,使用NUMPY

(t[i]*x+y[i,j]代表j中的j)
是一个。你也没有做任何比较,你只是把它扔进了真空

但请注意,这是
numpy
(我假设,因为您正在执行
y[I,j]
)。如果您使用
for
循环,则可能是做错了什么。取而代之的是按设计使用numpy。。。使用数组操作

T = [1,2]
J = range(5)
models = [(t*x) + y[i,j] >= 10 for j in J for i, t in enumerate(T)]
ta da全新的布尔数组。以下是一个例子:

t = np.arange(2)[:, np.newaxis]
comparison = (t*x + y) >= 10
哪个输出

import numpy as np

x = 1.5
y = np.random.randint(0, 16, (2, 5))
t = np.arange(2)[:, np.newaxis]

new = t*x + y
comparison = new >= 10

print(f'x = {x},\ny = \n{y},\n\nt = \n{t},\n\nnew = \n{new},\n\ncomp = \n{comparison}')

你想对这10个比较做什么?那不是一个循环,那是一个生成器表达式,它创建了一个生成器对象。你想对这10个比较做什么?那不是一个循环,那是一个生成器表达式,它创建了一个生成器对象