Ask Your Question

# vectorization of a matrix

In Python NumPy arrays implement the 'flatten' method (although this stacks the rows of the matrix, not the columns)

sage: A
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
sage: A.flatten()
array([1, 2, 3, 4, 5, 6, 7, 8, 9])
sage: A.T.flatten()
array([1, 4, 7, 2, 5, 8, 3, 6, 9])


In OCTAVE

octave: A
A =

8   1   6
3   5   7
4   9   2

octave: A(:)'
ans =

8   3   4   1   5   9   6   7   2


Is there a direct method .vectorize() of a matrix in SAGE?

Thanks in advance!

edit retag close merge delete

## 1 Answer

Sort by » oldest newest most voted

You can use the list method:

sage: a = random_matrix(ZZ,3)
sage: a
[22  3  0]
[-1 -1 -1]
[ 0  0 -1]
sage: a.list()
[22, 3, 0, -1, -1, -1, 0, 0, -1]


If you want a vector, you can do;

sage: vector(a.list())
(22, 3, 0, -1, -1, -1, 0, 0, -1)


On the other direction, you can do:

sage: M = a.parent()
sage: M
Full MatrixSpace of 3 by 3 dense matrices over Integer Ring
sage: M(a.list())
[22  3  0]
[-1 -1 -1]
[ 0  0 -1]
sage: M(a.list()) == a
True

more

## Comments

Thanks! I want to use vectorization to solve (linear matrix equation) "A*X*B=C", suppose A,B are both asymptotically stable.. the ideal case.., are there some tools in SAGE for equations of this type?

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2013-11-18 10:55:03 +0200

Seen: 1,502 times

Last updated: Nov 18 '13