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.Sat, 23 Nov 2019 20:06:34 +0100Absence of column vectorshttps://ask.sagemath.org/question/48860/absence-of-column-vectors/ I'm curious as to why column vecotrs seem to be non-existent in sage. To give you some context, I work with the following system:
R3 = IntegerModRing(3)
c_7_4 = [
[1, 0, -2, 0, 0, 0, 1],
[1, 1, 0, 0, -2, 0, 0],
[0, 1, 1, 0, 0, -2, 0],
[0, 0, 1, 1, 0, 0, -2],
[0, -2, 0, 1, 1, 0, 0],
[-2, 0, 0, 0, 1, 1, 0],
[0, 0, 0, -2, 0, 1, 1]
]
C3 = Matrix(R3, c_7_4)
B3 = C3.right_kernel().basis()
Clearly, the right kernel of C3 is a column vector, but if you run this code, you would find that
print(B3[0]) # returns a row vector
print(B3[0] * C3) # returns an answer
print(C3 * B3[0]) # returns an answer
Given that a column matrix should reasonably be written
[[a],[b]]
Why is this not the case? Specifically, is there a coding limitation to what the programmers can do which forces them to implement it in this way, or is there some mathematical usefulness to this which is beyond my understanding?
Thanks!
Sat, 23 Nov 2019 18:44:38 +0100https://ask.sagemath.org/question/48860/absence-of-column-vectors/Answer by vdelecroix for <p>I'm curious as to why column vecotrs seem to be non-existent in sage. To give you some context, I work with the following system:</p>
<pre><code>R3 = IntegerModRing(3)
c_7_4 = [
[1, 0, -2, 0, 0, 0, 1],
[1, 1, 0, 0, -2, 0, 0],
[0, 1, 1, 0, 0, -2, 0],
[0, 0, 1, 1, 0, 0, -2],
[0, -2, 0, 1, 1, 0, 0],
[-2, 0, 0, 0, 1, 1, 0],
[0, 0, 0, -2, 0, 1, 1]
]
C3 = Matrix(R3, c_7_4)
B3 = C3.right_kernel().basis()
</code></pre>
<p>Clearly, the right kernel of C3 is a column vector, but if you run this code, you would find that </p>
<pre><code>print(B3[0]) # returns a row vector
print(B3[0] * C3) # returns an answer
print(C3 * B3[0]) # returns an answer
</code></pre>
<p>Given that a column matrix should reasonably be written </p>
<pre><code>[[a],[b]]
</code></pre>
<p>Why is this not the case? Specifically, is there a coding limitation to what the programmers can do which forces them to implement it in this way, or is there some mathematical usefulness to this which is beyond my understanding? </p>
<p>Thanks! </p>
https://ask.sagemath.org/question/48860/absence-of-column-vectors/?answer=48861#post-id-48861There is no distinction between row vector and column vector in Sagemath
sage: v = vector((1,2,3))
sage: A = matrix(3, [1, -2, 3, 0, 1, -1, 2, 0, -2])
sage: A * v
(6, -1, -4)
sage: v * A
(7, 0, -5)
Sagemath vectors are different objects than 1 x n or n x 1 matrices. Matrices make a difference between rows and columns
sage: col_v = matrix(3, 1, [1, 2, 3])
sage: print(col_v)
[1]
[2]
[3]
sage: A * col_v
[ 6]
[-1]
[-4]
sage: row_v = matrix(1, 3, [1, 2, 3])
sage: print(row_v)
[1 2 3]
sage: row_v * A
[ 7 0 -5]
Of course both `A * row_v` and `col_v * A` will fail.Sat, 23 Nov 2019 20:06:34 +0100https://ask.sagemath.org/question/48860/absence-of-column-vectors/?answer=48861#post-id-48861