Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substituting MatrixSymbol in Matrix only changes first component #14540

Open
nschloe opened this issue Mar 20, 2018 · 2 comments
Open

Substituting MatrixSymbol in Matrix only changes first component #14540

nschloe opened this issue Mar 20, 2018 · 2 comments

Comments

@nschloe
Copy link
Contributor

nschloe commented Mar 20, 2018

When substituting a MatrixSymbol in a Matrix, only the first Matrix component is changed.

MVCE:

import sympy

a = sympy.MatrixSymbol('a', 2, 1)

A = sympy.Matrix([[a[0], a[1]**2]])                                             

a_vals = [1.0, 2.0]
print(A.subs(zip(a, a_vals)))

Output:

Matrix([[1.00000000000000, a[1, 0]**2]])

Expected output:

Matrix([[1.00000000000000, 4.00000000000000]])
@normalhuman
Copy link
Contributor

normalhuman commented Mar 20, 2018

It seems the conversion to dict, from our mailing list discussion, is needed sometimes.

>>> print(A.subs(dict(zip(a, a_vals))))
Matrix([[1.00000000000000, 4.00000000000000]])

Same for a tuple or list of tuples.

>>> print(A.subs(tuple(zip(a, a_vals))))
Matrix([[1.00000000000000, 4.00000000000000]])
>>> print(A.subs(list(zip(a, a_vals))))
Matrix([[1.00000000000000, 4.00000000000000]])

But I see no reason why passing an iterator to subs shouldn't work in this specific setup, so looks like a bug.

@ethankward
Copy link
Contributor

See also #13330

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants