Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Medium Matrices

New issue 2212 by asmeurer: Matrix([Matrix, …]) should work
http://code.google.com/p/sympy/issues/detail?id=2212

Here is my Matrix:

In [49]: a
Out[49]:
⎡1  -1  1   -1  1  -1  1   -1  1 ⎤
⎢                                ⎥
⎢2  0   -1  -2  0  1   2   0   -1⎥
⎢                                ⎥
⎢4  0   -2  0   0  0   -2  0   1 ⎥
⎢                                ⎥
⎢2  2   2   0   0  0   -1  -1  -1⎥
⎢                                ⎥
⎣1  1   1   1   1  1   1   1   1 ⎦

I want to construct the matrix

In [46]: b
Out[46]:
⎡1  -2  2   1  -2  1 ⎤
⎢                    ⎥
⎢2  -2  1   0  1   -1⎥
⎢                    ⎥
⎢4  0   -4  0  0   1 ⎥
⎢                    ⎥
⎢2  2   1   0  -1  -1⎥
⎢                    ⎥
⎣1  2   2   1  2   1 ⎦

which is a except the fourth column has been removed and added to the third, the seventh column has been removed and added to the third, and the eight column has been removed and added to the sixth (the matrix a represents the coefficients of partial derivatives with respect to (x1, x1), (x1, x2), (x1, x3), (x2, x1), etc., so for example, the partial with respect to (x2, x1) can just be added to the partial with respect to (x1, x2) and removed).

Now, I would have liked to have been able to do something like

b = Matrix(a[:,0], a[:,1] + a[:,3], a[:,2] + a[:,-3], a[:,4], a[:,5] + a[:,-2], a[:,-1])

or

b = Matrix([a[:,0], a[:,1] + a[:,3], a[:,2] + a[:,-3], a[:,4], a[:,5] + a[:,-2], a[:,-1]])

but those didn't work.  In fact,

b = Matrix([a[:,0].T, a[:,1].T + a[:,3].T, a[:,2].T + a[:,-3].T, a[:,4].T, a[:,5].T + a[:,-2].T, a[:,-1].T]).T

didn't even work.  The only that worked in the end was

b = Matrix([list(a[:,0].T), list(a[:,1].T + a[:,3].T), list(a[:,2].T + a[:,-3].T), list(a[:,4].T), list(a[:,5].T + a[:,-2].T), list(a[:,-1].T)]).T

Now, I don't know which of the above are consistent syntactically speaking, but it seems to me that at least the one without the list() calls should work (it would be nice if the first one worked too, but someone with a better handle on how this Matrix syntax should work should have a say on that).

P.S., is there a method of Matrix that would have made this easier to construct?

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to 
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to