Skip to content
Advertisement

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!

Advertisement

Answer

I see you want to “use the answer for a new equation”.

The previous equation solution is a, a list with 1 element [1]

then you can use a[0] in your next equation

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.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement