[英]TypeError: unsupported operand type(s) for /: 'list' and 'int' solution is an array
import numpy as np
from sympy import symbols, solve
x = symbols('x')
expr1 = -2*x + x**2 + 1
a = solve(expr1)
print(a)
p = a/2
expr2 = -4*x + x**2 + a
z = solve(expr2)
print(z)
5 a = solve(expr1)
6 print(a)
----> 7 p = a/2
8 expr2 = -4*x + x**2 + a
9 z = solve(expr2)
TypeError: unsupported operand type(s) for /: 'list' and 'int'
I solved an equation, the answer is an array.我解了一个方程,答案是一个数组。 I am trying to use the answer for a new equation.
我正在尝试使用新方程式的答案。 I wrote a sample code to explain my problem!
我写了一个示例代码来解释我的问题!
I see you want to "use the answer for a new equation".我看到您想“使用新方程式的答案”。
The previous equation solution is a
, a list with 1 element [1]
前面的方程解是
a
,一个包含 1 个元素的列表[1]
then you can use a[0] in your next equation那么你可以在你的下一个等式中使用 a[0]
expr2 = -4*x + x**2 + a[0]
z = solve(expr2)
print(z)
and p=a/2
is totally useless, you didn't use p
after that.并且
p=a/2
完全没用,在那之后你没有使用p
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.