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.Fri, 12 Aug 2022 13:52:50 +0200Looping around self defined indiceshttps://ask.sagemath.org/question/63646/looping-around-self-defined-indices/How can we effectively shorten the following piece of code:
g=graphs.CirculantGraph(8,[1,2])
v=g.vertices()
v1=set(v)-set([0,4])
v2=set(v)-set([1,5])
v3=set(v)-set([2,6])
v4=set(v)-set([3,7])
v5=set(v)-set([0,5])
v6=set(v)-set([1,4])
v7=set(v)-set([2,7])
v8=set(v)-set([3,6])
g1=g.subgraph(v1)
g2=g.subgraph(v2)
g3=g.subgraph(v3)
g4=g.subgraph(v4)
g5=g.subgraph(v5)
g6=g.subgraph(v6)
g7=g.subgraph(v7)
g8=g.subgraph(v8)
Like, I wish to loop on the indices `g(i)`. Instead of writing repeatedly `g1=subgraph(v1)` and so on, is there a way to loop arounfd the self defined index `g(i)`? Thanks beforehand.vidyarthiFri, 12 Aug 2022 13:52:50 +0200https://ask.sagemath.org/question/63646/Is it possible to speed up loop iteration in Sage?https://ask.sagemath.org/question/41375/is-it-possible-to-speed-up-loop-iteration-in-sage/I have a sage code that looks like this:
uni = {}
end = (l[idx]^(e[idx] - 1)) * (l[idx] + 1) # where end in my case is about 2013265922 but can also be much larger
for count in range(0, end):
i = randint(1, 303325737249669131)
if i in uni:
uni[i] += 1
else:
uni[i] = 1
So basically, I want to create very large number of random integers in the given range, check whether the number was already in the dictionary, if yes increment its count, if not initialize it to 1. But, this takes such a long time that it doesn't finish in a reasonable time. Is there any way to speed up this kind of loops in Sage (or Python)?ninhoSat, 03 Mar 2018 12:10:30 +0100https://ask.sagemath.org/question/41375/