ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 30 Nov 2020 03:16:09 -0600'method' object is not subscriptablehttps://ask.sagemath.org/question/54455/method-object-is-not-subscriptable/Starting with a graph G, I would like to make a list, the ith element of which is the graph G with its ith edge deleted.
def graphlist(G):
n=len(G.edges())
L=[G.copy().delete_edge(G.edges[i][0], G.edges[i][1]) for i in range(n)]
return L
When I enter the definition above, or a variation of it, I get the error
'method' object is not subscriptable
Thanks a lot for any suggestions!IngridMon, 30 Nov 2020 03:16:09 -0600https://ask.sagemath.org/question/54455/Is there a command in SAGE which is equivalent to GAP's "ShallowCopy" ?https://ask.sagemath.org/question/48819/is-there-a-command-in-sage-which-is-equivalent-to-gaps-shallowcopy/Dear SAGE forum,
I'd like to ask the following question:
>> Is there an equivalent in SAGE of GAP's "shallowcopy" ?
I'd like to associate to two times the same group two different character tables.
In GAP it is possible to do it as follows:
G:=AlternatingGroup(5);
H:=ShallowCopy(G);
ct_G:=CharacterTable(G);
and to then construct a different character table for H.
When I try to do this in SAGE, I always get the error message that G (!) already has a character table, although I wanted to assign a different (as far as the ordering of the rows and columns are concerned) character table to H (!)
EDIT (20.11.2019):
Here is part of my sage code:
HHHH=gap.Image(iso)
GGGG=gap.ShallowCopy(gap.Image(iso))
# Hier Einschub: CTBL wie in CTBLLib (falls vorhanden) wird nun gemacht:
gap.LoadPackage('"ctbllib"')
def CTBL_Breuer_fert(X):
StrDescr = gap.StructureDescription(X)
if gap.IsString(gap.StructureDescription(X)):
StrDescr = gap.StructureDescription(X)
CTBL_Breuer = gap.CharacterTable(StrDescr)
CTBL_Breuer_fertig = gap.CharacterTableWithStoredGroup(X,CTBL_Breuer)
else:
CTBL_Breuer_fertig = gap.CharacterTable(X)
return(CTBL_Breuer_fertig)
CTBL_Breuer_fertig = CTBL_Breuer_fert(HHHH)
# Hier Ende des Einschubs
ccl = [gap.ConjugacyClass(GGGG,x) for x in MAGMA_ccls_GG_for_GAP]
gap.SetConjugacyClasses(GGGG,ccl)
gap.SetUnderlyingGroup(tbl,GGGG)
gap.SetConjugacyClasses(tbl,ccl)
bij=[1..len(ccl)]
MyRecordFile = open("GAP_Record.txt",'w')
print >> MyRecordFile, "bij:=",
print >> MyRecordFile, bij,
print >> MyRecordFile, ";"
print >> MyRecordFile, "myrecfunct:=function()"
print >> MyRecordFile, "local RECOR;"
print >> MyRecordFile, "RECOR:=rec(bijection:=bij);"
print >> MyRecordFile, "return RECOR;"
print >> MyRecordFile, "end;"
MyRecordFile.close()
gap.Read('"GAP_Record.txt"')
recor=gap.myrecfunct()
gap.CompatibleConjugacyClasses(GGGG,ccl,tbl,recor)
CTBL=gap.CharacterTableWithStoredGroup(GGGG,tbl,recor)
After this last line (with CTBL=...) the error occurs. When I delete the lines between "# Hier Einschub..." and "# Hier Ende des Einschubs ", then the code works.
I would be grateful for any help.
Thanks in advance.BernWed, 20 Nov 2019 10:19:52 -0600https://ask.sagemath.org/question/48819/Copying a Matrixhttps://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 -0600https://ask.sagemath.org/question/40754/to_directed() affects original graphhttps://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 -0600https://ask.sagemath.org/question/36705/Deepcopy of a Matrix SageMathhttps://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 -0600https://ask.sagemath.org/question/36134/How to copy notebook worksheet data from one computer to anotherhttps://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 -0500https://ask.sagemath.org/question/26844/Using copy() for matrices still returns errorhttps://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 -0600https://ask.sagemath.org/question/10812/default worksheet for new usershttps://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 -0600https://ask.sagemath.org/question/9807/How do I copy paste from sage to microsoft office?https://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 -0600https://ask.sagemath.org/question/9766/Copy vectorshttps://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 -0500https://ask.sagemath.org/question/9445/Help! I have a problem with lists!https://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 -0500https://ask.sagemath.org/question/7727/