Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Attribute error - Sympy
#1
I want to use subs after using solve on a function, but the following error occurs. I have tried sympify and str but nothing changes. Any idea why?

x=Symbol('x')
f=2*x+2+y
x=solve(f,x)
g=x.subs(y,1)
Error:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-120-a4eecf671499> in <module>() 2 f=2*x+2+y 3 x=solve(f,x) ----> 4 g=x.subs(y,1) AttributeError: 'list' object has no attribute 'subs'
Quote
#2
solve() return a list and show LaTeX form in shell/editor/NoteBook that support this.
Can try sympify() on content in list first.
a = sympify(x[0])
g = a.subs(y,1)
>>> print(repr(g))
-3/2
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Attribute error in Dataframes deshanish 1 258 Jul-15-2020, 08:38 AM
Last Post: snippsat
  How to use list of symbols for sympy calculation in python? tanmaybhise 1 307 Mar-01-2020, 10:36 PM
Last Post: Gribouillis
  Next zero of a function on sympy VicenteM 0 575 Aug-21-2019, 04:58 PM
Last Post: VicenteM
  sympy psosmol 9 1,375 Mar-11-2019, 11:09 PM
Last Post: scidam
  NLTK Download Attribute error laila1a 1 2,643 Jan-27-2019, 12:03 AM
Last Post: Larz60+
  [split] np.arrange error - no attribute gyan 2 2,633 Aug-19-2018, 05:38 PM
Last Post: micseydel
  Attribute Error while using tensor flow pratheep 2 4,268 Mar-16-2018, 10:50 AM
Last Post: pratheep
  np.arrange error - no attribute pksherard 3 11,462 Aug-16-2017, 09:54 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)