ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 23 Jan 2018 12:44:19 -0600Copying a Matrixhttp://ask.sagemath.org/question/40754/copying-a-matrix/I'm trying to take the Singular Value Decomposition of the adjacency matrix of a graph A, but all my "reasonable" attempts at doing so have failed, see the code below.
I believe the problem has something to do with the matrix being immutable, so I've been trying to copy A into a different matrix M and then perform SVD on M. he only thing that I've found to work is to essentially build A from scratch, but there must be a better method.
sage: A=graphs.CycleGraph(3).adjacency_matrix()
#Method 1: Try and get SVD directly from A; gives error at last step.
#sage: A.change_ring(RDF)
#sage: A.SVD()
#Method 2: Try and copy A to a different matrix and then do SVD; gives error at last step.
# sage: M=copy(A)
# sage: M.change_ring(RDF)
# sage: M.SVD()
#Method 3: Build A up again from scratch and then do SVD; works, but is tedious.
sage: M=matrix(RDF,3,3)
sage: for i in [0..2]:
for j in [0..2]:
if(A[i,j]==1):
M[i,j]=1
sage: M.SVD()zorkkoiTue, 23 Jan 2018 12:44:19 -0600http://ask.sagemath.org/question/40754/Deepcopy of a Matrix SageMathhttp://ask.sagemath.org/question/36134/deepcopy-of-a-matrix-sagemath/I am creating a deepcopy of a Matrix in SageMath.
import copy
A = Matrix([[1,2],[3,4]]).augment(Matrix.identity(2), subdivide=True)
B = copy.deepcopy(A)
print A
print B
Gives me:
[1 2|1 0]
[3 4|0 1]
[1 2 1 0]
[3 4 0 1]
What is the correct way to deepcopy a matrix with the subdivision? Do I have to use:
B.subdivide(*A.subdivisions())
SageMath version 7.2, Release Date: 2016-05-15
I did not know about ask.sagemath before. This is a repost of stackoverflow .com /questions/41322359/deepcopy-of-a-matrix-sagemath (my karma is not enough to post links).kytickaSun, 01 Jan 2017 05:38:54 -0600http://ask.sagemath.org/question/36134/