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.Sun, 09 Apr 2023 19:44:13 +0200A function which sweep the indexes and doesn't stop at the first encounterhttps://ask.sagemath.org/question/67430/a-function-which-sweep-the-indexes-and-doesnt-stop-at-the-first-encounter/I would like to understand why the following code doesn't work
p=[-100,10,10,10,10,10,10,10,10,10,10]
[x/(1+.02)^(p.index(x)) for x in p]
what I was expecting is that for each $x$ `(p.index(x))` would be an other index. I remember that since $10$ is of multiplicity $9$, `(p.index(x))` is the index of the first occurence of $9$. So I ask if there is a function that sweep the index of all $x$ with or without multiplicity.CyrilleSun, 09 Apr 2023 19:44:13 +0200https://ask.sagemath.org/question/67430/Index without multiplicitieshttps://ask.sagemath.org/question/60254/index-without-multiplicities/I want really the vector zz. Unfortunatelly as 5 is present with multiplicity 2 the only index for 5 is 0. I want also 2.
How to obtain the desired return ?
So
z=[5,0,5,0,10,13,14,]
zz=[(z.index(v),v) for v in z if v!=0]
show(zz)
returns `[(0, 5), (0, 5), (4, 10), (5, 13), (6, 14)]` when I want `[(0, 5), (2, 5), (4, 10), (5, 13), (6, 14)]`.CyrillePTue, 14 Dec 2021 12:02:03 +0100https://ask.sagemath.org/question/60254/Indexing variables in a list comprehensionhttps://ask.sagemath.org/question/54503/indexing-variables-in-a-list-comprehension/ Suppose I create the polynomial ring R = PolynomialRing(QQ, ['lambda%s'%i for i in [1 .. g]] + ['psi%s'%i for i in [1 .. n]]).
If I want to create a list comprehension which creates a list of perhaps all the lambdas, what is the notation used at the beginning of the list comprehension?
i.e. [lambdai for i in [1 .. g]]. Laughematician760Tue, 01 Dec 2020 23:03:40 +0100https://ask.sagemath.org/question/54503/How do I extract base(3) and index (15) from $3^{15}$ in SageMath?https://ask.sagemath.org/question/50794/how-do-i-extract-base3-and-index-15-from-315-in-sagemath/ How do I extract base(3) and index (15) from $3^{15$} in SageMath?BSFUThu, 16 Apr 2020 16:24:00 +0200https://ask.sagemath.org/question/50794/Mapping 2-dimensional matrix index to a listhttps://ask.sagemath.org/question/45436/mapping-2-dimensional-matrix-index-to-a-list/Hi all,
I have a following matrix:
mat = matrix([[1,5,7],[3,10,12],[0,5,3]])
[ 1 5 7]
[ 3 10 12]
[ 0 5 3]
I got 3 parts from the matrix:
A = mat[[0,1,2],[0]]
[1]
[3]
[0]
B = mat[[1,2],[1,2]]
[10 12]
[ 5 3]
C = mat[[0],[1,2]]
[5 7]
To know that these 3 parts are not overlapping to each other, I have an idea to map the original matrix to 1-dimension array as IDs for each cell:
tt = copy(mat)
row = mat.nrows()
col = mat.ncols()
for x in range(row):
for y in range(col):
tt[x,y] = x*col+y
sage: tt
[0 1 2]
[3 4 5]
[6 7 8]
Then again I go over all coordinate that I took for A, B and C to collect these mapped ID.
Regarding to A,
cells_A = []
for i in range(0, 3):
for j in range(0, 1):
cells_A.append(tt[i, j])
sage: cells_A
[0, 3, 6]
Regarding to B:
cells_B = []
for i in range(1, 3):
for j in range(1, 3):
cells_B.append(tt[i, j])
sage: cells_B
[4, 5, 7, 8]
Regarding to C, similarly we have:
sage: cells_C = [1,2]
If size of union from these 3 cells is equal to the total size of A, B, and C, then I conclude no overlapping among them.
area = sum([A.nrows()*A.ncols(), B.nrows()*B.ncols(), C.nrows()*C.ncols()])
if len(set.union(*[set(cells_A), set(cells_B), set(cells_C)])) == area:
print("No overlapping parts")
However, this way requires lots of work and **SLOW**. Is there any already SageMath's Matrix feature supporting some steps above, especially a way to improve/avoid mapping index?imnvshWed, 13 Feb 2019 01:54:13 +0100https://ask.sagemath.org/question/45436/cycle indexhttps://ask.sagemath.org/question/10661/cycle-index/I know that S4 = SymmetricGroup(4)
P = S4.cycle_index()
will return the cycle index polynomial for S_4. What I want to do is substitute variables into this polynomial for Polya Enumeration problems. So for instance, how do I substitute x+y into the cycles of length 1, x^2+y^2 into the cycles of length 2, etc.ClemFanJC07Sat, 26 Oct 2013 19:31:51 +0200https://ask.sagemath.org/question/10661/Iterating over list of tupleshttps://ask.sagemath.org/question/36727/iterating-over-list-of-tuples/I am attempting to index into the y-coordinates of each tuple to count how many tuples have a y-coordinate of 0, 1, or 2 but am receiving an error message which looks like this:
Error in lines 1-1
Traceback (most recent call last):
File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 982, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 1, in <module>
TypeError: 'sage.rings.integer.Integer' object is not iterable
My code is below:
zero_count, one_count, two_count = 0
for i in range(len([list])):
if list[i][1] == 0:
zero_count += 1
elif list[i][1] == 1:
one_count += 1
else:
two_count += 1collegesistaSat, 25 Feb 2017 01:29:42 +0100https://ask.sagemath.org/question/36727/Doubly indexed sumhttps://ask.sagemath.org/question/26916/doubly-indexed-sum/ I would like to define a doubly indexed sum. Below is what I did:
V=list(var(','.join(['a_%d%d' % (i,n) for i in [0..5] for n in [0..5]])))
sum(a_in*binomial(5,i)*binomial(5,n) for i in [0..5] for n in [0..5])
I get the global name 'a_' is not defined error. I tried this when there is only one index and it works, but doesnt seem to work for double index. Can anyone help me with this?
cihanFri, 22 May 2015 17:53:04 +0200https://ask.sagemath.org/question/26916/Permutations indexed from zerohttps://ask.sagemath.org/question/23402/permutations-indexed-from-zero/Is there an option to have permutations indexed from zero instead of one, in other words can we have permutations on the integers 0 to n-1 instead of permutations on the integers 1 to n. This would be useful since indexation for lists, tuples, and iterables in general is usually from zero. Indices for variable names of generators of various algebraic structures, such as multivariate polynomial rings, finitely presented groups, etc., also start from zero.
I saw that `PermutationOptions` lets you choose how to display permutations, and whether to multiply them from left to right or right to left, but found nothing about having indices starting from zero versus one.
slelievreSun, 13 Jul 2014 19:10:27 +0200https://ask.sagemath.org/question/23402/