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!