sympy:AttributeError: 'list' object has no attribute 'subs'?
sympy:AttributeError: 'list' object has no attribute 'subs'?
我该如何解决
https://docs.sympy.org/latest/tutorial/basic_operations.html
from sympy import *
var('ax')
ans_a=ax
print("#",ans_a)
myValue={ax:6}
print("#",ans_a.subs(myValue))
#
var('bx')
ans_b=[bx]
print("#",ans_b)
myValue={bx:7}
print("#",ans_b.subs(myValue))
# ax
# 6
# [bx]
# AttributeError: 'list' object has no attribute 'subs'
# I want
# [7]
???
AttributeError: 'str' object has no attribute 'subs'
https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
我搜索了潜艇
from sympy import *
var('bx')
ans_b=[bx]
print("#",ans_b)
myValue={bx:7}
print("#", [ans.subs(myValue) for ans in ans_b])
#
var('m11 m12 m21 m22')
ans_M= Matrix([[m11,m12], [m21,m22]])
print("#",ans_M)
myValue={m11:11,m12:12,m21:21,m22:22}
print("#",ans_M.subs(myValue))
#
var('px py')
ans_P=Point(px,py)
print("#",ans_P)
myValue={px:1,py:2}
print("#",ans_P.subs(myValue))
# [bx]
# [7]
# Matrix([[m11, m12], [m21, m22]])
# Matrix([[11, 12], [21, 22]])
# Point2D(px, py)
# Point2D(1, 2)
我该如何解决
https://docs.sympy.org/latest/tutorial/basic_operations.html
from sympy import *
var('ax')
ans_a=ax
print("#",ans_a)
myValue={ax:6}
print("#",ans_a.subs(myValue))
#
var('bx')
ans_b=[bx]
print("#",ans_b)
myValue={bx:7}
print("#",ans_b.subs(myValue))
# ax
# 6
# [bx]
# AttributeError: 'list' object has no attribute 'subs'
# I want
# [7]
???
AttributeError: 'str' object has no attribute 'subs'
https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
我搜索了潜艇
from sympy import *
var('bx')
ans_b=[bx]
print("#",ans_b)
myValue={bx:7}
print("#", [ans.subs(myValue) for ans in ans_b])
#
var('m11 m12 m21 m22')
ans_M= Matrix([[m11,m12], [m21,m22]])
print("#",ans_M)
myValue={m11:11,m12:12,m21:21,m22:22}
print("#",ans_M.subs(myValue))
#
var('px py')
ans_P=Point(px,py)
print("#",ans_P)
myValue={px:1,py:2}
print("#",ans_P.subs(myValue))
# [bx]
# [7]
# Matrix([[m11, m12], [m21, m22]])
# Matrix([[11, 12], [21, 22]])
# Point2D(px, py)
# Point2D(1, 2)