I am trying to multiply a MatrixSymbol and Matrix and access the value inside it’s multiplication
a = MatrixSymbol('a', 1, 4)
l = Matrix([1,2,3,4])
print((a*l)[0])
This error IndexError:
Single indexing is only supported when the number of columns is known.
I would like to access the inner multiplication a[0][0]*1 + a[0][1]*2....
>Solution :
Maybe what you need is slicing rather than single indexing.
Something like this maybe:
In [50]: a*l
Out[50]:
⎡1⎤
⎢ ⎥
⎢2⎥
a⋅⎢ ⎥
⎢3⎥
⎢ ⎥
⎣4⎦
In [51]: (a*l)[0,:]
Out[51]:
⎛ ⎡1⎤⎞
⎜ ⎢ ⎥⎟
⎜ ⎢2⎥⎟
⎜a⋅⎢ ⎥⎟[:, :]
⎜ ⎢3⎥⎟
⎜ ⎢ ⎥⎟
⎝ ⎣4⎦⎠
In [52]: (a*l)[0,:].as_explicit()
Out[52]: [a₀₀ + 2⋅a₀₁ + 3⋅a₀₂ + 4⋅a₀₃]