1 | initial version |

Unfortunately, VectorSpace seems only to consider column vectors, not matrix as elements. So i do not know whether it is possible out of the box. A possible workaround is to "unfold" your matrix to a vector, and then refold result vector to get a matrix back.

Here is an example:

```
sage: p = 5
sage: F = GF(p)
sage: MM = MatrixSpace(F,2,3) ; MM
Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 5
sage: M1 = MM.random_element() ; M1
[2 0 0]
[1 4 3]
sage: M2 = MM.random_element() ; M2
[2 3 4]
[4 0 3]
sage: V = VectorSpace(F,MM.dimension()) ; V
Vector space of dimension 6 over Finite Field of size 5
sage: def unfold(M):
....: return V(M.list())
sage: def refold(UM):
....: return MM(UM.list())
sage: UM1 = unfold(M1)
sage: UM2 = unfold(M2)
sage: refold(UM1) == M1
True
sage: sp = V.span([UM1,UM2]) ; sp
UM1 + UM2 in sp
sage: UM1 + UM2 in sp
True
sage: UM3 = sp.random_element()
sage: M3 = refold(UM3) ; M3
[2 4 2]
[0 2 3]
sage: M3 in MM
True
```

2 | No.2 Revision |

Unfortunately, VectorSpace seems only to consider column vectors, not ~~matrix ~~matrix, as elements. So i do not know whether it is possible out of the box. A possible workaround is to "unfold" your matrix to a vector, do your computations in the span, and then refold result vector to get a matrix back.

Here is an example:

```
sage: p = 5
sage: F = GF(p)
sage: MM = MatrixSpace(F,2,3) ; MM
Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 5
sage: M1 = MM.random_element() ; M1
[2 0 0]
[1 4 3]
sage: M2 = MM.random_element() ; M2
[2 3 4]
[4 0 3]
sage: V =
```~~VectorSpace(F,MM.dimension()) ~~VectorSpace(F, MM.dimension()) ; V
Vector space of dimension 6 over Finite Field of size 5
sage: def unfold(M):
....: return V(M.list())
sage: def refold(UM):
....: return MM(UM.list())
sage: UM1 = ~~unfold(M1)
~~unfold(M1)
sage: UM2 = unfold(M2)
sage: refold(UM1) == M1
True
sage: sp = ~~V.span([UM1,UM2]) ~~V.span([UM1, UM2]) ; sp
~~
UM1 + UM2 in sp
~~Vector space of degree 6 and dimension 2 over Finite Field of size 5
Basis matrix:
[1 0 0 3 2 4]
[0 1 3 1 2 0]
sage: UM1 + UM2 in sp
True
sage: UM3 = sp.random_element()
sage: M3 = refold(UM3) ; M3
[2 4 2]
[0 2 3]
sage: M3 in MM
True

3 | No.3 Revision |

Unfortunately, ~~VectorSpace ~~`VectorSpace`

seems only to consider ~~column ~~row vectors, not ~~matrix, ~~matrices, as elements. So i do not know whether it is possible out of the box. A possible workaround is to "unfold" your ~~matrix to a vector, ~~matrices to vectors, do your computations in the span, and then refold result vector to get a matrix ~~back.~~back. Folding and unfolding being isomorphisms of vector spaces, you should be safe with your computations.

Here is an example:

```
sage: p = 5
sage: F = GF(p)
sage: MM = MatrixSpace(F,2,3) ; MM
Full MatrixSpace of 2 by 3 dense matrices over Finite Field of size 5
sage: M1 = MM.random_element() ; M1
[2 0 0]
[1 4 3]
sage: M2 = MM.random_element() ; M2
[2 3 4]
[4 0 3]
sage: V = VectorSpace(F, MM.dimension()) ; V
Vector space of dimension 6 over Finite Field of size 5
sage: def unfold(M):
....: return V(M.list())
sage: def refold(UM):
....: return MM(UM.list())
sage: UM1 = unfold(M1)
sage: UM2 = unfold(M2)
sage: refold(UM1) == M1
True
sage: sp = V.span([UM1, UM2]) ; sp
Vector space of degree 6 and dimension 2 over Finite Field of size 5
Basis matrix:
[1 0 0 3 2 4]
[0 1 3 1 2 0]
sage: UM1 + UM2 in sp
True
sage: UM3 = sp.random_element()
sage: M3 = refold(UM3) ; M3
[2 4 2]
[0 2 3]
sage: M3 in MM
True
```

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.