ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 09 Jan 2011 16:06:01 +0100Converting kernel to matrixhttps://ask.sagemath.org/question/7859/converting-kernel-to-matrix/I construct a matrix A and compute its kernel by
A = matrix(GF(2),vectors)
B = A.kernel()
Now I want to convert B to a matrix, such that I can use .nrows() and other matrix-methods, how to do that?Sun, 09 Jan 2011 07:15:35 +0100https://ask.sagemath.org/question/7859/converting-kernel-to-matrix/Answer by DSM for <p>I construct a matrix A and compute its kernel by</p>
<pre><code>A = matrix(GF(2),vectors)
B = A.kernel()
</code></pre>
<p>Now I want to convert B to a matrix, such that I can use .nrows() and other matrix-methods, how to do that?</p>
https://ask.sagemath.org/question/7859/converting-kernel-to-matrix/?answer=11947#post-id-11947(Showing my work).
The first thing I tried was the obvious:
<pre><code>sage: vectors = [[1,0,1],[1,0,1],[1,1,0]]
sage: A = matrix(GF(2),vectors)
sage: B = A.kernel()
sage: matrix(B)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[...]
ValueError: Invalid matrix constructor. Type matrix? for help
</code></pre>
which didn't work. So looked at B:
<pre><code>sage: B
Vector space of degree 3 and dimension 1 over Finite Field of size 2
Basis matrix:
[1 1 0]
</code></pre>
and saw that it clearly knows about the matrix I think you're looking for. In Sage, functionality often lives inside objects, so if you type help(B) or or type "B." and then tab, you can see the list of internal functions, and I found both .matrix and .basis_matrix. I think either should work here, so:
<pre><code>sage: M = B.basis_matrix()
sage: M
[1 1 0]
sage: type(M)
<type 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>
sage: M.nrows()
1
</code></pre>
Is that what you were after?Sun, 09 Jan 2011 08:50:18 +0100https://ask.sagemath.org/question/7859/converting-kernel-to-matrix/?answer=11947#post-id-11947Comment by Mustafa for <p>(Showing my work).</p>
<p>The first thing I tried was the obvious:</p>
<pre><code>sage: vectors = [[1,0,1],[1,0,1],[1,1,0]]
sage: A = matrix(GF(2),vectors)
sage: B = A.kernel()
sage: matrix(B)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[...]
ValueError: Invalid matrix constructor. Type matrix? for help
</code></pre>
<p>which didn't work. So looked at B:</p>
<pre><code>sage: B
Vector space of degree 3 and dimension 1 over Finite Field of size 2
Basis matrix:
[1 1 0]
</code></pre>
<p>and saw that it clearly knows about the matrix I think you're looking for. In Sage, functionality often lives inside objects, so if you type help(B) or or type "B." and then tab, you can see the list of internal functions, and I found both .matrix and .basis_matrix. I think either should work here, so:</p>
<pre><code>sage: M = B.basis_matrix()
sage: M
[1 1 0]
sage: type(M)
<type 'sage.matrix.matrix_mod2_dense.Matrix_mod2_dense'>
sage: M.nrows()
1
</code></pre>
<p>Is that what you were after?</p>
https://ask.sagemath.org/question/7859/converting-kernel-to-matrix/?comment=22314#post-id-22314That is it! Thank you.Sun, 09 Jan 2011 16:06:01 +0100https://ask.sagemath.org/question/7859/converting-kernel-to-matrix/?comment=22314#post-id-22314