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.Wed, 04 Oct 2023 08:23:15 +0200Column space of a matrixhttps://ask.sagemath.org/question/73746/column-space-of-a-matrix/Hello Everyone,
I am new to Sage, and I am trying to use its linear algebra capabilities.
As a first exercise, I am trying to compute the column space of a matrix:
A = matrix([[1,3,8],[1,2,6],[0,1,2]])
According to the documentation, the column space of A is given by A.column_space(). This function returns me:
- Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 1]
[ 0 1 -1]
when I was expecting
[1 3]
[1 2]
[0 1]
I clearly missed something. Any clues? With Maxima, I got the expected colum space.
I thank you in advance for any help.
Best,
alefWed, 04 Oct 2023 08:23:15 +0200https://ask.sagemath.org/question/73746/Putting a vector into part of a row of a matrixhttps://ask.sagemath.org/question/50841/putting-a-vector-into-part-of-a-row-of-a-matrix/So from the link given here- https://ask.sagemath.org/question/8366/editing-entries-of-matrix/
From the answer given, I see that to replace a row (say row 1) on a matrix by a list say List 1, I just do
K[1, :] = vector(List1)
For example,
K = Matrix(QQ, 6, 8)
A priori, this is just the 0 matrix. Now writing
K[1, :] = vector([1, 1, 1, 1, 1, 1, 1, 1])
will replace my first row of my 6 x 8 matrix with the entries all 1's.
However, what if I want to replace say row 1 but only the last 6 entries
so I will have `[0, 0, 1, 1, 1, 1, 1, 1]`. Of course, I can just type out
K[1, :] = vector([0, 0, 1, 1, 1, 1, 1, 1])
but this is not viable for larger matrices.
An example would be say my `K = Matrix(QQ, 40, 80)` and I have a list given by `L1 = [1, 1, 1, 1]`.
Suppose I want to replace the row 1 with 40th-43rd entry being `L1`.
Method 1- Type out 76 zeros and do `K[1, :] = vector(L1 with 76 zeros)`. This is not really ideal.
Method 2- Replace entry by entry. This is also not ideal if my `L1` is say of length 20.
Is there a way to just say something like `K[1, 40-43] = vector([L1])`?whatupmattSat, 18 Apr 2020 18:04:49 +0200https://ask.sagemath.org/question/50841/Absence 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!
KraigSat, 23 Nov 2019 18:44:38 +0100https://ask.sagemath.org/question/48860/create matrix as having a subset of columns from another matrixhttps://ask.sagemath.org/question/24035/create-matrix-as-having-a-subset-of-columns-from-another-matrix/ I need to get a new matrix generated by selecting a subset of columns from another matrix, given a list (or tuple) of column indices.
The following is the code I am working on (there is a bit more than just the attempt to create a new matrix, but might be interesting for you to have some context).
A = matrix(QQ,[
[2,1,4,-1,2],
[1,-1,5,1,1],
[-1,2,-7,0,1],
[2,-1,8,-1,2]
])
print "A\n",A
print "A rref\n",A.rref()
p = A.pivots()
print "A pivots",p
with the following output:
A
[ 2 1 4 -1 2]
[ 1 -1 5 1 1]
[-1 2 -7 0 1]
[ 2 -1 8 -1 2]
A rref
[ 1 0 3 0 0]
[ 0 1 -2 0 0]
[ 0 0 0 1 0]
[ 0 0 0 0 1]
A pivots (0, 1, 3, 4)
Now I expected to find easily a method from `matrix` objects which allowed to construct a new matrix with a subset of columns by just giving the tuple `p` as parameter, but could not find anything like that.
Any ideas on how to solve this *elegantly* in a sage-friendly way? (avoiding `for` loops and excess code)
thanks!stablumFri, 05 Sep 2014 21:52:40 +0200https://ask.sagemath.org/question/24035/Replace rows an columns by zeros in a numpy arrayhttps://ask.sagemath.org/question/10395/replace-rows-an-columns-by-zeros-in-a-numpy-array/Hi expers.
¿How can I replace rows an columns by zeros (or other values) in a numpy array?
Waiting for your answers.
Thanks a lot.mresimulatorMon, 29 Jul 2013 12:13:08 +0200https://ask.sagemath.org/question/10395/