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.Thu, 07 Jan 2021 02:39:32 -0600Centering the cells of a table and the use of tiny sizehttps://ask.sagemath.org/question/55144/centering-the-cells-of-a-table-and-the-use-of-tiny-size/I change my question to clarify.
In the following code (I have integrated the solution for `\tiny`):
First define a function:
def All_pref(cand=["A", "B", "C", "D"], code=1) :
ncand = len(cand)
Scand = sorted(Set(cand))
all_pref = Arrangements(Scand, ncand).list()
all_pref1 = [str(Word(x)) for x in all_pref]
if code == 1:
return ncand
if code == 2:
return all_pref1
Then use it:
cand = ["A", "B", "C", "D"]
ne1 = [18, 16, 14, 12, 11, 20, 19, 14, 16, 12, 2, 1, 0, 0, 20, 16, 13, 15, 11, 10, 9, 8, 7, 5]
ne = ne1
Ap = All_pref(cand, 2)
cond1 = ['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
cond2 = [""] + [r'${}$'.format(*w) for w in cand]
cond3 = [r'${}$'.format(*w) for w in cand]
t1 = table([ne], header_row=cond1)
rank = [[x.find(l) for x in Ap] for l in cand]
score_de_Borda = [[abs(x.find(l) - len(cand)) for x in Ap] for l in cand]
t2 = table(rank, header_row=cond1, header_column=cond2)
total_score_de_Borda = [add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
# t3 = table(total_score_de_Borda, header_column=cond3)
show(cond3,total_score_de_Borda)
everything works fine apart from the `header_column=cond3` (without it I have no problem) and as `show(cond3, total_score_de_Borda)` shows, the two elements have the same length.CyrilleWed, 06 Jan 2021 03:11:06 -0600https://ask.sagemath.org/question/55144/Pb with headers in table()https://ask.sagemath.org/question/55166/pb-with-headers-in-table/Here is the forgotten function which list all the preferences on a list of candidates
def All_pref(cand=["A","B","C","D"],code=1) :
ncand=len(cand)
Scand=sorted(Set(cand))
all_pref=Arrangements(Scand,ncand).list()
all_pref1=[str(Word(x)) for x in all_pref]
if code==1 :
return ncand
if code==2 :
return all_pref1
I have a problem with the following function :
# Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0)
# cond = 0 redonne la répartition des préférences
# cond = 1 donne le classement des candidats sur chaque type de préférences
# cond = 2 donne les scores sur chaque candidat
# cond = 2 donne l'accumulation des scores sur chaque candidat
# cond = 3 déclare le vainqueur au sens de Borda.
def Borda(cand=["A","B","C","D"],ne=[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],cond=0) :
Ap=All_pref(cand,2)
cond1=['$\\tiny${}{}{}{}$'.format(*w) for w in Ap]
cond2 =[""]+ [r'${}$'.format(*w) for w in cand]
cond3 =[r'${}$'.format(*w) for w in cand]
t1=table([ne])#,header_row=cond1)
rank=[[x.find(l) for x in Ap] for l in cand]
score_de_Borda=[[abs(x.find(l)-len(cand)) for x in Ap] for l in cand]
t2=table(rank)#,header_row=cond1,header_column=cond2)
total_score_de_Borda=[add([score_de_Borda[j][i]*ne[i] for i in range(24)]) for j in range(len(cand))]
t3=table(score_de_Borda)#,header_column=cond3)
max_total_score_de_Borda=max(total_score_de_Borda)
ind_max_total_score_de_Borda=total_score_de_Borda.index(max_total_score_de_Borda)
vainqueur_de_Borda=cand[ind_max_total_score_de_Borda]
if cond==0 :
return t1
if cond==1 :
return t2
if cond==2 :
return t3
if cond==3 :
return total_score_de_Borda
if cond==4 :
return vainqueur_de_Borda
and here is a call to the different variations.
show(LatexExpr(r"\text{Le tableau des rangs est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],1))
show(LatexExpr(r"\text{Le tableau des scores est :}"))
show(Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],2))
show(LatexExpr(r"\text{Les scores totaux de chaque candidat sont :}"))
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],3)
show(LatexExpr(r"\text{Le vainqueur d'un décompte à la Borda est : }"),
Borda(["A","B","C","D"],[18,16,14,12,11,20,19,14,16,12,2,1,0,0,20,16,13,15,11,10,9,8,7,5],4),LatexExpr(r"."))
All is fine but if inside the function i remove the`#` and allow the header(s), I have an error which I do not understand since some time it works and some time not. (I am working with sagemath 9.2 under windows).CyrilleThu, 07 Jan 2021 02:39:32 -0600https://ask.sagemath.org/question/55166/Title for tablehttps://ask.sagemath.org/question/55147/title-for-table/ Is there a way to gice a title to a table above the row header or under the table. It would be nice.CyrilleWed, 06 Jan 2021 05:10:25 -0600https://ask.sagemath.org/question/55147/Colors in tablehttps://ask.sagemath.org/question/54413/colors-in-table/This is a nice table with the help of two of you (many thanks).
A = [[10] * 10, [100] + [0] * 9, [11.1] * 9 + [0]]
A.extend([[20] * 5 + [0] * 5, [50/2^n for n in range(10)]])
D = deepcopy(A) # copie A dans D en conservant A intacte
# on arrondit uniquement les lignes qui en ont besoin
D[2] = list(matrix(RDF, A[2]).round(3)[0])
D[4] = list(matrix(RDF, A[4]).round(3)[0])
# on construit la table
hr = [r"${\color{red} n}$" for n in (1 .. 10)]
hc = ["", r"${\definecolor{energy}{RGB}{200, 8, 21}\color{energy}\text{Équirépartition}}$", r"${\definecolor{energy}{RGB}{200, 8, 21}\color{energy}\text{Tout pour un}}$", r"${\definecolor{energy}{RGB}{200, 8, 21}\color{energy}\text{Un déshérité}}$"]
hc += [r"${\definecolor{energy}{RGB}{200, 8, 21}\color{energy}\text{Injustice pour 1/2 population}}$", r"${\definecolor{energy}{RGB}{200, 8, 21}\color{energy}\text{Injustice croissante}}$"]
t = table(D, header_row=hr, header_column=hc)
show(t)
I added colors in the header row. But adding them in the header column
does not work since the elements of the header need to be formatted.
So what can I do? And if I want some background colors in the cells
and change the colors of the cell's fonts?CyrilleFri, 27 Nov 2020 02:52:46 -0600https://ask.sagemath.org/question/54413/Table frame not showing in Jupyter Notebook and inconsistent in other environmentshttps://ask.sagemath.org/question/50600/table-frame-not-showing-in-jupyter-notebook-and-inconsistent-in-other-environments/ Hello, Sage community!
The `table` command in Sage has this useful option called `frame`. If I set `frame=True` in SageCell, CoCalc, the Sage terminal and SageTeX, the result is the expected: a frame is shown for the corresponding table. However, the same command does not work properly in Jupyter Notebooks. Also, the results are quite different in SageCell and CoCalc.
The following three images show the result of executing the following commands:
rows = [[100,2,3], [4,5,60]]
t = table(rows, frame=True)
show(t)
This is the result in SageCell:
![image description](/upfiles/15861892266090416.png)
This is the result in CoCalc:
![image description](/upfiles/1586189242468030.png)
This is the result in Jupyter (executed using `sage -n jupyter`):
![image description](/upfiles/15861892732930594.png)
Here are my questions:
1. Why is the `frame=True` option not working in Jupyter?
2. Why the difference in the results?
3. Is there any way to make these results consistent through these environments?dsejasMon, 06 Apr 2020 11:10:42 -0500https://ask.sagemath.org/question/50600/Latex multicolumn is not recognizedhttps://ask.sagemath.org/question/48614/latex-multicolumn-is-not-recognized/ HI
R0 = GF(3)
print R0.addition_table()
print R0.multiplication_table()
show(R0.addition_table())
latex(R0.addition_table())
ortolljTue, 05 Nov 2019 07:13:25 -0600https://ask.sagemath.org/question/48614/How to save table output in an exportable mannerhttps://ask.sagemath.org/question/38252/how-to-save-table-output-in-an-exportable-manner/Hello! I am a sage novice trying to export a table output to some image format (so that it might be shared). I tried using the .save() function as so:
my_table1 = table(my inputs)
result = my_table1.transpose()
result.save('here')
My table outputs properly after I run the program (not featured), but for some reason I receive the following error when I try and save the table:
"Error! /home/sage/Documents/here.sobj is not UTF-8 encoded
Saving disabled.
See Console for more details."
Any help in exporting this table is greatly appreciated. Additionally, if you require any more information please do not hesitate to ask!
EDIT: I am working in Jupyter for Sage on a browser via localhost/8000; not sure if that matters.ethanzellThu, 13 Jul 2017 23:53:29 -0500https://ask.sagemath.org/question/38252/Multiple tables in Notebook's output?https://ask.sagemath.org/question/36448/multiple-tables-in-notebooks-output/ Hi!
Trying to print more than one table in the output of Sage's Notebook cell, with fancy-printing:
table([[0]])
table([[1]])
but only the last one is shown (checked in Firefox and Chrome in Linux). Currently found workaround is:
html.table([[0]])
html.table([[1]])
but it gives a deprecation warning, or:
html(table([[0]])._html_() + table([[0]])._html_())
which seems to work fine.EugeneSat, 04 Feb 2017 05:33:32 -0600https://ask.sagemath.org/question/36448/how to render html or latex tables in jupyter notebook?https://ask.sagemath.org/question/34782/how-to-render-html-or-latex-tables-in-jupyter-notebook/Dear all,
I moved a few of my sagenb worksheets to jupyter, but I don't seem to be able to nicely display tables. For example:
blah = [('Header1', 'Header2'), (1,2), (3,4), (5,6)]
html.table(blah)
returns the html code for the table, but does not render it. Is there a way to display a nicely typeset table in the jupyter notebook using the sage kernel?
Cheers
StanstanFri, 09 Sep 2016 07:34:33 -0500https://ask.sagemath.org/question/34782/sage.cloud'sheet is too smallhttps://ask.sagemath.org/question/24718/sagecloudsheet-is-too-small/ when run below,the code is lost
E = EllipticCurve_from_j(Qp(7,3)(0));E;html(table(E.automorphisms(),frame="True")).transpose())
show(EllipticCurve_from_j(GF(3,'a')(0)).automorphisms())cjshThu, 30 Oct 2014 23:24:29 -0500https://ask.sagemath.org/question/24718/export data and labels in cvs filehttps://ask.sagemath.org/question/23407/export-data-and-labels-in-cvs-file/Hi experts!
I have the Numpy arrays `AAA=[a1,a2,...]` and `BBB=[b1,b2,...]`. I know that I can export these arrays doing:
np.savetxt('array AAA.csv', AAA, delimiter=',')
np.savetxt('array BBB.csv', BBB, delimiter=',')
I wanna export one csv file that include both arrays + labels, in this way:
AAA | BBB
----------
a1 | b1
a2 | b2
. | .
. | .
. | .
How can I do that?
Waiting for your answers.
Thanks a lot.
Best regardsmresimulatorSun, 13 Jul 2014 18:08:16 -0500https://ask.sagemath.org/question/23407/Undefined control sequence when showing multiplication tablehttps://ask.sagemath.org/question/10774/undefined-control-sequence-when-showing-multiplication-table/Using Sage Version 5.12,
sage: Z5=Integers(5)
sage: show(Z5.multiplication_table())
The output is:
An error occurred.
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian) (format=pdflatex 2013.11.25)
(...)
! Undefined control sequence.
<argument> 2\ex
l.40 ...ace{40mm}\[{\setlength{\arraycolsep}{2\ex}
(...)
How to get a table to display correctly with show?eyrtuweyrtMon, 25 Nov 2013 07:13:19 -0600https://ask.sagemath.org/question/10774/latex.table() function?https://ask.sagemath.org/question/8602/latextable-function/Can Sage construct latex code of table? Something like html.table, but with tex-output instead of html-output.EugeneSat, 31 Dec 2011 03:40:09 -0600https://ask.sagemath.org/question/8602/large html.tablehttps://ask.sagemath.org/question/10464/large-htmltable/I have noticed this strange behavior:
when I try to print a large table such as
html.table([['x' for j in range(10)] for k in range(1000)])
in the output I have
WARNING: Output truncated!
full_output.txt
...
followed by a portion of the table, and the link to the file "full_output.txt" open up a page with the html code of the table. So far it is ok. But if I try to change the table in the same cell, as for example
html.table([['y' for j in range(10)] for k in range(1000)])
the file "full_output.txt" does not change: I still see the output of the previous command with a table whose entries are all 'x' and not 'y'.
It seams that once the file "full_output.txt" is created it is not modified by the following commands on the same cell. (note that in a different cell the output is correct only the first time I run it)
Can anyone reproduce this?
('Sage Version 5.10, Release Date: 2013-06-17', firefox 23.0, osx 10.6.8)abcFri, 23 Aug 2013 04:25:25 -0500https://ask.sagemath.org/question/10464/large tablehttps://ask.sagemath.org/question/10453/large-table/If I try to print large table in the notebook with too many columns then each row is split into various lines. For example in the output of
table([['z' for j in range(num_column)] for k in range(10)])
with num_column larger then 18, the rows are split. (it is not the case if I use for example html(table(...)).
Is it possible to visualize correctly tables with many columns with the standard table command? abcFri, 23 Aug 2013 04:37:19 -0500https://ask.sagemath.org/question/10453/Very strange error with html in sagenotebookhttps://ask.sagemath.org/question/10293/very-strange-error-with-html-in-sagenotebook/Hello!
I have function:
def my_table():
s = """<table border=1>
<tr><td>1</td><td>a</td><td>{0}</td></tr>
<tr><td>2</td><td>b</td><td>{1}</td></tr>
<tr><td>3</td><td>c</td><td>{2}</td></tr>
<tr><td>4</td><td>d</td><td>{3}</td></tr>
<tr><td>5</td><td>e</td><td>{4}</td></tr>
<tr><td>6</td><td>f</td><td>{5}</td></tr>
<tr><td>7</td><td>g</td><td>{6}</td></tr>""".format(0, 1, 2, 3, 4, 5, 6)
html(s)
I create new worksheet in sage notebook, in 1st cell I paste this code. Then I press shift+enter. In 2nd cell I type:
my_table()
and also press shift+enter. Then I press "save and quit". After I closed this worksheet I open it and see that there are 2 tables and cells don't work correctly. When I try evaluate 2nd cell, the sage can't perform calculation.
What do I wrong? Please help me. Thanks.AndreWinSat, 29 Jun 2013 00:04:00 -0500https://ask.sagemath.org/question/10293/Table of primeshttps://ask.sagemath.org/question/9939/table-of-primes/Hello,
I'm trying to create a table (or matrix, what comes first) with the first rank is the primes_range from 2 to 29 and the first column with primes_range from 2 to 29 too.
Then, I want to add i[0] + j[0] = element 4 using the values above.
The reason for that is that I want to create a table of even elements based on Goldbach conjecture that says that an even is the sum of two equal (or different) primes:
4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
The problem is that an even number can be written in several ways, example:
24 = 5 + 19
24 = 7 + 17
24 = 11 + 13 and so on..
The number 200 = 3 + 197 . So, my problem is to 'remember' in a for/loop the number 3. When I'm close to the even 200 the number variable that holds the first prime is far away from 3.
So, I think the solution maybe can be a combination or a value table or a matrix.
Thank you in advance.
P.S.: This is not a homework.Luiz Roberto MeierSat, 23 Mar 2013 10:44:58 -0500https://ask.sagemath.org/question/9939/subtract two data tableshttps://ask.sagemath.org/question/9218/subtract-two-data-tables/ ta1=[[1,1],[2,2],[3,3]]
ta2=[[1,1],[2,1],[3,1]]
ta1_j=[]
ta2_j=[]
for i,j in ta1:
ta1_j.append(j)
for i,j in ta2:
ta2_j.append(j)
ta3_j=[]
for i,j in zip(ta1_j,ta2_j):
ta3_j.append(i-j)
ta3_i=[]
for i,j in ta1:
ta3_i.append(i)
ta3=zip(ta3_i,ta3_j)
ta3
I want to subtract table2 from table1 in such way that X stays the same and only Y values are subtracted.
The above code works for me, but is there a nicer, better and easier way to subtract tables ?
b0f00narchWed, 08 Aug 2012 02:36:06 -0500https://ask.sagemath.org/question/9218/matrix and latexhttps://ask.sagemath.org/question/8831/matrix-and-latex/I want to create a matrix with my results and then to obtain the output in latex code. However, the first column are natural number, and the second one are not integers, so I can´t create a matrix with different inputs (Am I right?). How can I do?emiliocbaTue, 27 Mar 2012 14:22:59 -0500https://ask.sagemath.org/question/8831/getting blank cells in html.tablehttps://ask.sagemath.org/question/7956/getting-blank-cells-in-htmltable/I would like the following to give me a blank spot in a table in the notebook.
html.table([[1,None],[3,4]])
Unfortunately, it instead LaTeXs it to `\mathrm{None}`, which jsmath can't handle in any case. But I don't really want that behavior of `latex()` to change, but rather to figure out how to get the blank spot in the table without actually hacking the code of `html.table` (this is supposed to work on a server which is only updated once a semester).
kcrismanFri, 18 Feb 2011 04:26:51 -0600https://ask.sagemath.org/question/7956/Tables of graphics?https://ask.sagemath.org/question/7519/tables-of-graphics/I recall seeing a function that would allow one to make a table (or a series) of graphics. For example, if I wanted to display 10 plots in a series, how would I do this?
Thanks in advance.Eviatar BachFri, 10 Dec 2010 17:37:13 -0600https://ask.sagemath.org/question/7519/