Re: [sympy] Matrix vector multiplication

2023-11-01 Thread Aaron Meurer
What is the type of your vector x? If it is a Matrix, this is just the
way that SymPy works. It represents "vectors" as a 1 x n matrix. If it
is an object from the sympy.vector module then I'm not sure.

I would recommend not using NumPy to manipulate SymPy objects like
that. NumPy should only be used for numeric values and ideally you
should only do so after converting your SymPy expression to a NumPy
function with lambdify(). You lose out on the benefits of using SymPy
if you store SymPy objects in a NumPy array. See
https://docs.sympy.org/dev/explanation/best-practices.html#separate-symbolic-and-numeric-code

Aaron Meurer

On Wed, Nov 1, 2023 at 8:15 PM Lenni Lemoy  wrote:
>
> Hi everybody,
>
> I just started using SymPy, and tried to multiply a matrix M by a vector x 
> holding sympy.symbols.
>
> I expected that M*x will be a vector again, but it is a matrix holding 
> elements M_i,j*x_j.
>
> Is that the intended behavior or am I doing something wrong? I looked for 
> another method I could use but found nothing adequate. Currently, I use 
> np.sum(M*x, axis=1) to obtain the vector result, but this seems a little 
> awkward.
>
> Thanks already for any info on this! :)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/5dfb60ca-617f-429a-b23c-c59c67cc98c3n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6JOiQjmJi53pCsiJrBOz238zHYz800UtbU9pFyuXsEYtA%40mail.gmail.com.


[sympy] Matrix vector multiplication

2023-11-01 Thread Lenni Lemoy
Hi everybody, 

I just started using SymPy, and tried to multiply a matrix M by a vector x 
holding sympy.symbols. 

I expected that M*x will be a vector again, but it is a matrix holding 
elements M_i,j*x_j. 

Is that the intended behavior or am I doing something wrong? I looked for 
another method I could use but found nothing adequate. Currently, I use 
np.sum(M*x, axis=1) to obtain the vector result, but this seems a little 
awkward.

Thanks already for any info on this! :)

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/5dfb60ca-617f-429a-b23c-c59c67cc98c3n%40googlegroups.com.