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/to_directed() affects original graphhttp://ask.sagemath.org/question/36705/to_directed-affects-original-graph/ I've stumbled on what I think is a bug. When you create a directed graph from some original graph and then making changes on the new, this can affect the old one. I'm not sure if it should be like this and one should always copy the graph first. Here's a minimal example that for be gives an error "KeyError: 0".
G1=graphs.RandomGNP(5,0.5)
G1.plot(save_pos=True)
G2=G1.to_directed()
G2.delete_vertex(0)
G2.add_vertex(5)
G2.plot()
G1.plot()AckslThu, 23 Feb 2017 04:27:23 -0600http://ask.sagemath.org/question/36705/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/How to copy notebook worksheet data from one computer to anotherhttp://ask.sagemath.org/question/26844/how-to-copy-notebook-worksheet-data-from-one-computer-to-another/ Hi, I have a number of sage notebook worksheets in my old ubuntu laptop. I need to get a copy of them to my new ubuntu laptop as well as to another win8.1 laptop. Need to work with then locally without internet connection in my boat, so it's a critical issue for me.simoSat, 16 May 2015 10:34:21 -0500http://ask.sagemath.org/question/26844/Using copy() for matrices still returns errorhttp://ask.sagemath.org/question/10812/using-copy-for-matrices-still-returns-error/I want to take the zero matrix and assign entries to make a new matrix. I understand that the zero matrix is immutable and I need to make a copy, but copy() isn't working. Here is what I put in:
A = copy(matrix(3,3,0))
A[0][0]=1
and the error says vector is immutable; please change a copy instead (use copy())
What am I doing wrong?
Thank you!EEChisholmFri, 06 Dec 2013 18:46:44 -0600http://ask.sagemath.org/question/10812/default worksheet for new usershttp://ask.sagemath.org/question/9807/default-worksheet-for-new-users/Hi,
i am running a sage notebook server,
is it possible to generate a worksheet, which is automatically copied in the notebook of new users?
So they need not to take a copy of published worksheets, but get this one right in there notebook after creating a new account?
I mean something like /etc/skel in linux
Thanks a lot.msageThu, 14 Feb 2013 22:09:31 -0600http://ask.sagemath.org/question/9807/How do I copy paste from sage to microsoft office?http://ask.sagemath.org/question/9766/how-do-i-copy-paste-from-sage-to-microsoft-office/Hello. I'm unable to copy n paste anything from Sage to anywhere else in my computer.. I mean i cant copy paste from sage to microsoft office, or noteopad.. im using windows 7.. can someone help me please, what should i do..ShaMon, 04 Feb 2013 13:02:02 -0600http://ask.sagemath.org/question/9766/Copy vectorshttp://ask.sagemath.org/question/9445/copy-vectors/Hello everyone,
I have the following problem:
I have two vectors v = vector(QQ, [1,1]), w = vector(QQ, [3,3]).
I want to copy the coefficients of w into v. I can't set v = w
directly, beacuse v is used as a value in some dictionaries.
I could loop over the list() of the vectors, but I was wondering if
there is some *better* way to copy all of the entries.
Example from comment:
> l = {1: v}; v.set(1,2) Now l == {1: (1, 2)}, but v = copy(w) does not change lMathmonFri, 19 Oct 2012 02:25:33 -0500http://ask.sagemath.org/question/9445/Help! I have a problem with lists!http://ask.sagemath.org/question/7727/help-i-have-a-problem-with-lists/Hello!
I am a real beginner in Sage, I have just started th use it. In fact this is my first programing language, so I have some difficulties with it... Now I needed a command, which determins all the k-element subset of [1,2,...,N]. Since I don't found a command like this, I decided to write a program... :-) And now I simple don't understand while my program doesn't work corrrectly! Could you explain me? It is a bit longish, so sorry for this.
def eve(A,N):
"""
the largest elem in the list A which can
be increased by 1, such that the resulting list contains only
different elements less than N. Originally
A should contain different elements in increasing order.
"""
ev = len(A)-1
while A[ev] == ev+N-len(A):
ev=ev-1
return ev
def rakovetkezo(A,N):
"""
Increases the eve(A,N)nt element by 1, and all the other elements
after this element are succesive natural numbers
"""
Q=A
ev=eve(Q,N)
x=Q[ev]
for i in range(ev,len(Q)):
Q[i]=x+i-ev+1
return Q
def reszhalmazok(N,k):
"""
It should (but it doesn't) return the k-element
subset of [1,2,...,N]
"""
X=range(k)
B=[range(k)]
ev=eve(X,N)
while ev != -1:
X=rakovetkezo(X,N)
B.append(X)
ev = eve(X,N)
return B
Now `reszhalmazok(5,3`) should return `[[0,1,2], [0,1,3],...]` but it returns something completely different, aaand I don't see why, and how could be improve it?
KatikaKatikaFri, 15 Oct 2010 22:42:24 -0500http://ask.sagemath.org/question/7727/