On 05/20/2010 05:19 PM, Robert Bradshaw wrote:
On May 20, 2010, at 3:15 PM, VictorMiller wrote:

Does the Matrix class have methods for vertical and horizontal joins
of matrices (as in Magma)? That is

if A is an m by n matrix and B is an r by n matrix then
VerticalJoin(A,B) would by the (m+r) by n matrix with A "on top" and B
"on the bottom". Similarly, if A is m by n and B is m by r then
HorizontalJoin(A,B) would be an m by (n+r) matrix with A "on the left"
and B "on the right". I though that Numeric Python used to have
something like this with a method called concatenate, but I can't find
that in numpy.

You're probably looking for stack and augment.

sage: M = random_matrix(ZZ, 3, 3)
sage: M.stack(M)
[ -1 1 -5]
[ 72 -2 1]
[ -2 2 -20]
[ -1 1 -5]
[ 72 -2 1]
[ -2 2 -20]
sage: M.augment(M)
[ -1 1 -5 -1 1 -5]
[ 72 -2 1 72 -2 1]
[ -2 2 -20 -2 2 -20]


Also block_matrix, which internally uses stack and augment:

sage: M=random_matrix(ZZ,3,4)
sage: M
[-1 -1  2  1]
[ 1  3  2 -3]
[-1 -1  2 -1]
sage: block_matrix([M,M],nrows=2,ncols=1)
[-1 -1  2  1]
[ 1  3  2 -3]
[-1 -1  2 -1]
[-----------]
[-1 -1  2  1]
[ 1  3  2 -3]
[-1 -1  2 -1]
sage: block_matrix([M,M],nrows=1,ncols=2)
[-1 -1  2  1|-1 -1  2  1]
[ 1  3  2 -3| 1  3  2 -3]
[-1 -1  2 -1|-1 -1  2 -1]

Thanks,

Jason

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to