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, 28 May 2023 14:25:28 +0200Render Latex in IPython notebook and display on output linehttps://ask.sagemath.org/question/31607/render-latex-in-ipython-notebook-and-display-on-output-line/So let's say I generate a Latex expression like so
def polar_gradient(f):
return (derivative(f, x), derivative(f, r), derivative(f,theta))
x, r, theta = var('x', 'r', 'theta')
f = r * sin(theta)
grad = polar_gradient(f)
expr=latex(grad)
Is there a way I can render expr and display it on the output line in an Ipython notebook?
xentity1xWed, 16 Dec 2015 19:11:42 +0100https://ask.sagemath.org/question/31607/Help writing a scripthttps://ask.sagemath.org/question/68803/help-writing-a-script/Write a script that takes two arguments the first being either pi/e and the second being an integer between 1 and 200. If the first argument is x and second argument is n then your script is expected to display the nth digit of x after the decimal point. The script should display a message if n is outside the range and exit elegantly. If the number of arguments is less than 2, then too the script should display an appropriate message and exit properly.
Trying in SageMath Jupyter notebook
import sys
if len(sys.argv) < 3:
print("Usage: python assn2a.py {pi/e} n")
sys.exit(1)
x = sys.argv[1]
n = int(sys.argv[2])
if n < 1 or n > 200:
print("n should be an integer between 1 and 200.")
sys.exit(1)
if x == "pi":
value = str(pi)
elif x == "e":
value = str(e)
else:
print("Invalid value for x. Please choose 'pi' or 'e'.")
sys.exit(1)
digit = value.split(".")[1][n-1]
print(digit)rishant001Sun, 28 May 2023 14:25:28 +0200https://ask.sagemath.org/question/68803/problem with float not equals but should be equals? problemhttps://ask.sagemath.org/question/57268/problem-with-float-not-equals-but-should-be-equals-problem/ Dear Collegues
I have a problem with checking equals float numbers:
code:
d = 0.2
u = d - 1
up = d - 0.5
r = u
for i in range(1,7):
r = r + 0.1
print(i,r,up)
if r == up :
print("equal","r",r,"=","up",up)
break;
output:
1 -0.700000000000000 -0.300000000000000
2 -0.600000000000000 -0.300000000000000
3 -0.500000000000000 -0.300000000000000
4 -0.400000000000000 -0.300000000000000
5 -0.300000000000000 -0.300000000000000
6 -0.200000000000000 -0.300000000000000
in line 5 -> it should print that are equals...
what is wrong?MiroslawTue, 25 May 2021 19:52:28 +0200https://ask.sagemath.org/question/57268/πΈπΏπ’ππππ.ππππ.πππππππ’.π·ππΌπ»ππππππhttps://ask.sagemath.org/question/51375/ipythoncoredisplayhtmlobject/What means
`<πΈπΏπ’ππππ.ππππ.πππππππ’.π·ππΌπ»ππππππ>`
It seems to be a complaint since nothing happens when this warning is displayed but it's not always the case? I found no documentation on this.CyrilleMon, 11 May 2020 19:48:59 +0200https://ask.sagemath.org/question/51375/LaTeX shortcuts in iPython Notebookhttps://ask.sagemath.org/question/43437/latex-shortcuts-in-ipython-notebook/ Is there a way to load a file containing many LaTeX shortcuts (like `\newcommand{...}{...}`) into an iPython notebook, so that these can be used throughout?
Or is it possible to add to a (hopefully hidden) cell? If so, what would be the syntax?lrfinottiTue, 21 Aug 2018 22:43:46 +0200https://ask.sagemath.org/question/43437/Typeset mode in iPython notebookhttps://ask.sagemath.org/question/24919/typeset-mode-in-ipython-notebook/Hi, I'm trying to set typeset mode = True using the iPython notebook in Sage 6.4, but I don't find how to do it. Is it already implemented?jllbWed, 19 Nov 2014 17:07:44 +0100https://ask.sagemath.org/question/24919/Make ipython notebook world-viewable?https://ask.sagemath.org/question/24995/make-ipython-notebook-world-viewable/ Is there a way to make a cloud.sagemath.org iPython notebook viewable (read-only) by anyone who has a link to it? I'd like an easy way to share notebook contents with people who have not yet signed up for SageMath Cloud accounts. Clearly I can download as HTML and put a static copy on my own web server, but perhaps there is a more direct way?
ashmanskasTue, 25 Nov 2014 16:07:06 +0100https://ask.sagemath.org/question/24995/Integrate SAGE Jupyter Notebook in Anaconda Python Distributionhttps://ask.sagemath.org/question/32741/integrate-sage-jupyter-notebook-in-anaconda-python-distribution/ Hello, i'm Eduardo Vieira a Mechanical Engineering student from Venezeula. I use Python for everything and now i'm looing to Sage but is there a way to integrate Sage with the Jupyter Notebook? To get sage in the Notebook i have to run sage -ipython but i want to have the Sage kernel avaible when i run jupyter notebook.
I am using the Anaconda python distribution in Ubuntu Linux.
Thanks and sorry for my english, i know it is really bad.
EduardoJVWed, 09 Mar 2016 02:42:59 +0100https://ask.sagemath.org/question/32741/Sage on Jupyter with ipywidgets, matplotlibhttps://ask.sagemath.org/question/31326/sage-on-jupyter-with-ipywidgets-matplotlib/Hi all,
I've spent about two days now trying to get Sage to work nicely on Jupyter.
Still, I have the following two problems:<br /><br />
1. ipywidgets (and I have found no docu on the web that would hint to this problem) does not show any output and fails on commands like interact(f,x=10)<br /><br />
2. backend support for matplotlib (I've tried all the "solutions" that come up on a google search, I have tk/tcl installed on my system, sage compiled from scratch with $SAGE_MATPLOTLIB_GUI="yes" but it does not find TKInter for tk support, not to mention that the sage pyqt4 package fails compiling)
**concerning 1.**<br />
I ran the following code on jupyter with Sage 6.9 kernel
from __future__ import print_function;
from ipywidgets import interact;
def f(x): return(x);
interact(f,x=10);
this gives (besides various traceback output)
ValueError: 10 cannot be transformed to a Widget
I have the following version:
sage -installed | grep ipywidgets
ipywidgets.............................. 4.0.2
**concerning 2.**<br />
I've tried to recompile sage -f matplotlib after export SAGE_MATPLOTLIB_GUI="yes"
BUILDING MATPLOTLIB
matplotlib: yes [1.4.3]
python: yes [2.7.9 (default, Dec 3 2015, 20:58:38) [GCC
4.8.4]]
platform: yes [linux2]
...
OPTIONAL BACKEND EXTENSIONS
macosx: no [Mac OS-X only]
qt5agg: no [PyQt5 not found]
qt4agg: no [PyQt4 not found]
pyside: no [PySide not found]
gtk3agg: no [Requires pygobject to be installed.]
gtk3cairo: no [Requires cairocffi or pycairo to be installed.]
gtkagg: no [Requires pygtk]
tkagg: no [TKAgg requires Tkinter.]
wxagg: no [requires wxPython]
gtk: no [Requires pygtk]
agg: yes [installing]
cairo: no [cairocffi or pycairo not found]
windowing: no [Microsoft Windows only]
running on:
> uname -a
Linux host 3.16.0-53-generic #72~14.04.1-Ubuntu SMP Fri Nov 6 18:17:23 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
> locate libtk8.6.so
/usr/lib/x86_64-linux-gnu/libtk8.6.so
> locate libtcl8.6.so
/usr/lib/x86_64-linux-gnu/libtcl8.6.so
> locate Tkinter.py
/usr/lib/python2.7/lib-tk/Tkinter.py
/usr/lib/python2.7/lib-tk/Tkinter.pyc
Furthermore, (on another machine for some magic reason I could not figure out, I have TKAgg as backend available), it seems I cannot use %matplotlib inline as with a python kernel. The only option seems to have the plots in a new window.
Can anybody help? I'm frustrated to the point that I'm nearly planning on using the Python kernel and running the needed sage code via exec. But, quite honestly, that would be horrendous ;-)camoldFri, 04 Dec 2015 19:27:10 +0100https://ask.sagemath.org/question/31326/jupyter (ipython notebook) kernel math displayhttps://ask.sagemath.org/question/30163/jupyter-ipython-notebook-kernel-math-display/I'm trying to set up sage as a [jupyter](https://jupyter.org/) (ipython notebook 4.0+) kernel on my local machine.
To do this, I have installed sage in /usr/local/sage, and set up a kernel using the SageKernelSpec tool (following instructions [here](http://doc.sagemath.org/html/en/reference/repl/sage/repl/ipython_kernel/install.html)).
My sage kernel.json looks like this:
> {"display_name": "Sage 6.9", "argv": ["/usr/local/sage/sage", "-python", "-m", "sage.repl.ipython_kernel", "-f", "{connection_file}"]}
The kernel starts from within jupyter, and I am able to run sage. However, math text is not rendered. As an example:
x, y = var('x y')
show(x/y)
> \newcommand{\Bold}[1]{\mathbf{#1}}\frac{x}{y}
The problem seems to be that the notebook is not recognising and formatting mathjax input properly. I have tried manually linking the sage mathjax library to ipython using:
use_local_mathjax()
But it still does not work.
I *can* get a properly functioning sage notebook by entering:
sage -n ipython
in terminal, but when starting the notebook from my standard jupyter environment (i.e. choosing the kernel from the dropdown list), the mathtype is not rendered.
I can't work out what's going on... any pointers appreciated.
Thanks!oscarbransonWed, 21 Oct 2015 03:25:38 +0200https://ask.sagemath.org/question/30163/What to do for using the IPython notebook?https://ask.sagemath.org/question/26902/what-to-do-for-using-the-ipython-notebook/ I've installed the git version of sage (currently 6.7), but I'm not sure how to use the IPython notebook. I've tried
./sage -ipython notebook
but it does not work.
Am I doing it right?
PD: I installed `libssl-dev`
$ sudo aptitude install libssl-dev DoxWed, 20 May 2015 21:45:25 +0200https://ask.sagemath.org/question/26902/Manipulate a csv file using ipython notebookhttps://ask.sagemath.org/question/26731/manipulate-a-csv-file-using-ipython-notebook/ I have a csv file which includes:
Branch Ra L C Rb
1 1 10 1 1
2 13 100 15 6
How can I get an output from this csv file which will look like`
Branch1:
Ra1 ndT nd1b 1
L1 nd1b nd1c 10
C1 nd1c 0 1
Rb1 nd1c 0 1
Branch2:
Ra2 ndT nd2b 13
L2 nd2b nd2c 100
C2 nd2c 0 15
Rb2 nd2c 0 6sydneyWed, 06 May 2015 08:19:31 +0200https://ask.sagemath.org/question/26731/Manipulation of a csv file using ipython notebookhttps://ask.sagemath.org/question/26732/manipulation-of-a-csv-file-using-ipython-notebook/ I have a csv file which includes:
Branch Ra L C Rb
1 1 10 1 1
2 13 100 15 6
How can I get an output from this csv file which will look like`
Branch1:
Ra1 ndT nd1b 1
L1 nd1b nd1c 10
C1 nd1c 0 1
Rb1 nd1c 0 1
Branch2:
Ra2 ndT nd2b 13
L2 nd2b nd2c 100
C2 nd2c 0 15
Rb2 nd2c 0 6sydneyWed, 06 May 2015 08:22:34 +0200https://ask.sagemath.org/question/26732/Why are my edits to an IPython Notebook being "undone" after a few secondshttps://ask.sagemath.org/question/25713/why-are-my-edits-to-an-ipython-notebook-being-undone-after-a-few-seconds/I have been using this notebook for several days without issue. I opened it up today and tried to edit some code in a cell. As I was still typing, the edit disappeared and my cursor moved to the beginning of the cell. Nothing shows up in the Log other than I opened the notebook. I am not sure what's going on. avonmollWed, 04 Feb 2015 21:33:15 +0100https://ask.sagemath.org/question/25713/Interacts not working in IPython notebookhttps://ask.sagemath.org/question/25344/interacts-not-working-in-ipython-notebook/I'm running Sage 6.4.1 (on Ubuntu 14.04 and Firefox 34.0) and using the IPython notebook. It's a great interface, but interactives aren't working. For example, the following brings up a bunch of HTML rather than an actual interactive.
@interact
def test(a=(-3,3)):
p=plot(a*sin(x), (x,-2*pi, 2*pi))
show(p)
Do interactives work differently in the IPython notebook?jaiaWed, 24 Dec 2014 21:42:00 +0100https://ask.sagemath.org/question/25344/IP-Notebooks and extensions, Sage versus Sage Cloudhttps://ask.sagemath.org/question/23226/ip-notebooks-and-extensions-sage-versus-sage-cloud/ In Sage Math Cloud I can open an IP:Notebook, execute
%load_ext sage
and Sage runs whithin the IP:Notebook.
Trying to do the same with my local IPython fails. I get an ImportError:
../IPython/core/extensions.py in load_extension(self, module_str)
96 if module_str not in sys.modules:
97 with prepended_to_syspath(self.ipython_extension_dir):
---> 98 __import__(module_str)
99 mod = sys.modules[module_str]
100 if self._call_load_ipython_extension(mod):
ImportError: No module named 'sage'
Where can I get this module 'sage'? Or is it private to SMC?
-- **EDIT** -- [26-11-2014]
According to slelievre below:
"In Sage 6.4.beta6 or later, $ sage --notebook=ipython should also work."
In fact I get:
sage --notebook=ipython
Sage Version 6.4, Release Date: 2014-11-14 β
File "/sage-6.4/src/bin/sage-notebook", line 180, in <module>
launcher(unknown)
File "/sage-6.4/src/bin/sage-notebook", line 69, in __init__
from sage.repl.notebook_ipython import SageNotebookApp
File "/sage-6.4/local/lib/python2.7/site-packages/sage/repl/notebook_ipython.py", line 14, in <module>
from IPython.html.notebookapp import NotebookApp
File "/sage-6.4/local/lib/python2.7/site-packages/IPython/html/notebookapp.py", line 62, in <module>
from tornado import httpserver
File "/sage-6.4/local/lib/python2.7/site-packages/tornado-3.1.1-py2.7.egg/tornado/httpserver.py", line 30, in <module>
import ssl
File "/sage-6.4/local/lib/python/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
Peter LuschnySat, 05 Jul 2014 17:12:23 +0200https://ask.sagemath.org/question/23226/How to import in an Ipython-Notebook on SMC?https://ask.sagemath.org/question/24385/how-to-import-in-an-ipython-notebook-on-smc/ Consider the following scenario (which I tested at SageMathCloud), with an Ipython-Notebook:
%load_ext sage
import trans
def A():
""" Computes the factorial """
n, f = 1, 1
while True:
f = f*n
yield f
n += 1
def binomial_trans(seq):
""" Input : seq sequence generator """
S = []
n = 0
while True:
S.append(seq.next())
yield sum(binomial(n, k) * S[k] for k in (0..n))
n += 1
f = binomial_trans(A())
print [f.next() for _ in range(10)]
This works. Now I would like to outsource the function 'binomial_trans' in a file trans.py and compute
f = trans.binomial_trans(A())
print [f.next() for _ in range(10)]
This does not work. The error message is: AttributeError: 'float' object has no attribute 'n'
What can I do to make the import work together with Sage in an Ipython-Notebook?
Peter
Peter LuschnyFri, 03 Oct 2014 22:30:55 +0200https://ask.sagemath.org/question/24385/Cimporting Sage classes with the new Sage IPython notebookhttps://ask.sagemath.org/question/23460/cimporting-sage-classes-with-the-new-sage-ipython-notebook/Sage Version 6.2, Release Date: 2014-05-06,
Unbuntu 12.04, 64 bit version
Hello,
I am using the new Sage IPython notebook and would like to cimport the class "Matrix_mod2e_dense" in a cython cell.
(1) Here is a minimum *working* example in the Sage IPython command line (also works on a SageMathCloud terminal), and that I would like to transpose in the Ipython notebook :
from sage.all import *
cython("#clang C++\n from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense")
(A similar statement works in the old Sage notebook, and also on the SageMathCloud notebook).
(2) And here is a (nearly) minimum *non working* example in the Sage IPython notebook, nor on a SageMathCloud IPython notebook :
from sage.all import *
%load_ext sage
%load_ext cythonmagic
%%cython
#clang C++
from sage.all import *
cimport numpy as np
#It is worth noting that the *cimport numpy* works. But when I add this last statement:
from sage.matrix.matrix_mod2e_dense cimport Matrix_mod2e_dense
It then says :
> .cache/ipython/cython/_cython_magic_9842ede087c20823a43baddf277ba52c.pyx:6:0:
> 'Matrix_mod2e_dense.pxd' not found
3) So everything leads me to think that it is the cimport command that is badly interpreted by the Ipython Notebook.
Does someone has a solution to make (1) work in the Sage Ipython Notebook ? (For instance, what should I add/remove in the cythonmagic.py file ? I couldn't attach mine to this post, but could publish/send in a way or another if this might help)
Finaly, I mention similar posts, but not exactly on the same issue, so which could not help me :
http://ask.sagemath.org/question/2575/importing-sage-functions-into-cython ---
http://ask.sagemath.org/question/2766/about-cython-and-the-main-sage-commands ---
http://ask.sagemath.org/question/23226/ip-notebooks-and-extensions-sage-versus-sage-cloud/ ---
http://stackoverflow.com/questions/24532549/making-sage-work-with-ipython
Thank you for your help !
MatthieumrambaudThu, 17 Jul 2014 19:16:06 +0200https://ask.sagemath.org/question/23460/Sage ranges in IP-Notebooks on CSMhttps://ask.sagemath.org/question/11073/sage-ranges-in-ip-notebooks-on-csm/On cloud.sagemath
%load_ext sage
def f(n):
for k in (1..n):
print n
f(5)
gives
AttributeError
----> 1 f(Integer(5))
in f(n)
2
3 def f(n):
----> 4 for k in (1..n):
5 print n
AttributeError: 'float' object has no attribute 'n'
Does "%load_ext sage" not invoke the Sage preparser?
petropolisSat, 28 Jun 2014 05:57:11 +0200https://ask.sagemath.org/question/11073/