Ask Your Question

ADuC812's profile - activity

2021-03-10 17:32:14 +0200 received badge  Famous Question (source)
2018-12-15 18:10:17 +0200 received badge  Notable Question (source)
2018-08-13 19:08:34 +0200 received badge  Taxonomist
2018-06-04 15:51:11 +0200 received badge  Nice Answer (source)
2018-01-22 00:38:46 +0200 received badge  Popular Question (source)
2017-10-02 22:31:41 +0200 received badge  Self-Learner (source)
2017-09-14 10:24:09 +0200 commented answer plot sage Graphics() from jupyter notebok in CoCalc

Just for completeness - I include here pyplot solution which is also not perfect but at least does not require temporary files

import matplotlib.pyplot as plt
from sage.all import *
figu = plt.figure() # you may set the size here
main_plot = figu.add_axes((0.2,0.2,0.7,0.7))
Gr.matplotlib('a.svg', figure=figu, sub=main_plot)
2017-09-10 18:44:42 +0200 commented answer plot sage Graphics() from jupyter notebok in CoCalc

My idea is to use Python kernel but import sage as a library (actually, only specific features, incl. plotting)

2017-09-08 16:23:18 +0200 received badge  Nice Question (source)
2017-09-08 14:24:35 +0200 asked a question plot sage Graphics() from jupyter notebok in CoCalc

I want to use sage as a python library from jupyter notebok in CoCalc. I have a problem with Sage plotting:

from sage.all import *

This code outputs "Graphics object consisting of 1 graphics primitive".

Pyplot plotting works fine. There are a number of old posts with the similar problem ( ex., some of them recommend changing matplotlib backend with %matplotlib inline which does not help. Is there a way to output sage Graphics() inline without using pyplot?

2015-03-18 09:38:06 +0200 received badge  Nice Answer (source)
2015-03-17 14:54:43 +0200 answered a question performing a higher resolution FFT

I am not sure if this is what you want, but if you add some number of zeros in the end of your input list you will get higher resolution (just more points) in the output. This trick works best if your signal decays to zero in the end (and is zero at the beginning). It does not, however, improve the actual resolution of the FFT, for example in case the characteristic frequency in your signal is not an exact multiple of the sampling rate. In the latter case, you can use Hamming window for example to improve resolution.

2015-03-17 14:30:00 +0200 asked a question Changes in figure HTML layout in 6.5?

I am trying to layout the figures drawn by plot() using raw html. In 6.3 and 6.4 it worked, but got broken in 6.5. My code is:

print('Plots of sine and cosine\nare to the left ')

In 6.3, the tags are embedded exactly into the places where the show() function is called, but in 6.5 all the figures are in the end and not embedded into the table. Was this change intentional? Can anyone propose a workaround? My application relies a lot on such formatting.

2015-02-16 09:08:40 +0200 received badge  Famous Question (source)
2014-06-29 03:15:05 +0200 marked best answer a fast function taking either variable or collection as argument

I want to create a function which takes either variable or collection as argument. If the input is any kind of collection, function should be taken of every element in it and return a numpy array of results. Currently, I do in this way:

def simplefunc(x):
    <some code here> # it is assumed that x is a single variable
    return <some single result>
def arrayfunc(x):
    try: #check if we have a collection 
        x_iterator = iter(x)
    except TypeError: #this is a single expression
        return simplefunc(x)
    else: # iterate through iterable x
        for xx in x:
        return numpy.array(ret)

It works as is, however, I do not think this is the fastest way possible,especially the method to figure out if the input is a collection. I also do not like that strings are considered as collections and split to chars (I can stand it though). Is there a more elegant way?

I tried also to call arrayfunc() recursively on each element of collection (instead of simplefunc()), to handle collections of collections in the same way, however, it runs into infinite loop on strings. I have to check if the input is a string explicitly.

2013-12-27 09:38:56 +0200 marked best answer does ubuntu ppa update 32-bit version ??


I maintain the PPA. As no longer provides Ubuntu 12.04 32bit binaries, I no longer repackage 32bit. I hope that is fixed over the next few months.

In the meantime, get a binary for 13.04 on, or build from source.

Regards, Jan

2013-12-27 04:07:10 +0200 commented answer does ubuntu ppa update 32-bit version ??

No, That is all fine with my system, except that it is 32 bit, and for 32 bit architecture there is NO 5.13 version of Sage in PPA !!

2013-12-27 03:31:01 +0200 marked best answer does ubuntu ppa update 32-bit version ??

The ppa repository is quite frequently updated. As you can see on this page, the currently abvailable version is 5.13, which is the one right before 6.0. Note that for a non-developper, the 6.0 version does not offers more functionality than 5.13, since there are only changes concerning the development workflow, not the mathematics features.

2013-12-27 03:30:59 +0200 commented answer does ubuntu ppa update 32-bit version ??

Then something is wrong with my system. I have ensured the repo is in the sources.list, and apt does not complain on update, but looks that it does not update actually. Sorry for taking your time.

2013-12-26 06:23:14 +0200 asked a question does ubuntu ppa update 32-bit version ??

I have installed sage from ubuntu ppa into my 32-bit ubuntu as described at but it did not update since 5.8.

How regularly this repository is updated? Will 6.0 be there?

2013-11-28 15:39:35 +0200 received badge  Notable Question (source)
2013-08-27 17:05:03 +0200 answered a question does sage server API work in 5.10?

Looks that I can set up a twisted conch ssh server as described here to run it in sage, and execute everything that comes through ssh channel. Testing this approach I had to install only pyasn1 into sage, which is a conch dependency, otherwise the example server from the link above works out-of-the-box.

Later I will maybe post a complete solution, as soon as I get there...

2013-08-26 16:44:43 +0200 received badge  Commentator
2013-08-26 16:44:43 +0200 commented answer does sage server API work in 5.10?

I have noticed that the essential documentation page is old, therefore was asking how much relevant it is. Seems that completely irrelevant. The sage cell server might look fine, but I am a complete noob in modern web technologies that are used in this server. I can just hope that it does not require to write half of a browser to get something written onto that cell and evaluated. Oh, and I need to get the result as well ... Can anyone tell me what to start with (or maybe even some examples???)

2013-08-25 17:26:41 +0200 asked a question does sage server API work in 5.10?

I am trying to run a simple notebook server to use API described here and here

I run the following code in sage command line:


'Sage Version 5.10, Release Date: 2013-06-17'

sage: from sagenb.notebook.notebook_object import test_notebook                                     
sage: passwd = str(randint(1,1<<128))                                                               
sage: nb = test_notebook(passwd, secure=False, interface='localhost', port=Integer(9000), verbose=True, directory=None)

Instead of running server, I get the following:

AttributeError                            Traceback (most recent call last)
<ipython-input-8-6fc45872bdcd> in <module>()
----> 1 nb = test_notebook(passwd, secure=False, interface='localhost', port=Integer(9000), verbose=True,directory=None)

/opt/sage/devel/sagenb/sagenb/notebook/notebook_object.pyc in test_notebook(admin_passwd, secure, directory, port, interface, verbose)
    267     nb = _notebook.load_notebook(directory)
--> 268     nb.set_accounts(True)
    269     nb.add_user('admin', admin_passwd, '')
    270     nb.set_accounts(False)
AttributeError: 'Notebook' object has no attribute 'set_accounts'

I have also tried to connect to a "normal" sage server created by notebook() via 'simple' URL:


which returns error 404

Does the sage server API work in sage 5.10? Is there a workaround how to create such server? Is there any other way to execute some sage code remotely?

2013-06-23 17:56:25 +0200 received badge  Notable Question (source)
2012-11-23 08:41:04 +0200 asked a question a way to set a per-user SageObject.db() folder

I like the way Sage allows any SageObject to be dumped by SageObject.db('name') command. However, setting up a multi-user server I have found that all notebook users share the same directory in $HOME/.sage/db

Moreover, if a server has a pool with several local users to run the code, which is recommended in tutorials for public servers, these local users all have different $HOME! (this can be worked around by symlinking for example)

Is there a way to set a single db() directory per notebook user, and not for pool user?

2012-10-21 17:37:23 +0200 received badge  Popular Question (source)
2012-09-19 04:35:59 +0200 received badge  Popular Question (source)
2012-01-19 11:37:33 +0200 commented answer combine sage plot with matplotlib

after messing a bit with aspect ratio, added an update about it. It would be good to add it to your example as well

2012-01-19 08:58:09 +0200 received badge  Necromancer (source)
2012-01-19 08:04:36 +0200 answered a question combine sage plot with matplotlib

For some time, I was looking for a way how to generate several sage Graphics() objects and plot them on a matplotlib canvas in an arbitrary arrangement, using .matplotlib() function. It went out not being straightforward. I decided that the solution I've found may be interesting for others as well. The following code produces a plot with a nice inset:

#make some graphs
# plot main figure
from matplotlib.figure import Figure
figure = Figure() # you may set the size here
main_plot = figure.add_axes((0.2,0.2,0.7,0.7))
g.matplotlib('a.svg', figure=figure, sub=main_plot)
# plot an inset
inset = figure.add_axes((0.6,0.2,0.3,0.3))
g_ins.matplotlib('a.svg', figure=figure, sub=inset)
# display graph (note that only single sage Graphics object has to be saved )'a.svg', figure=figure, sub=inset)

UPD: if figures are drawn strangely, add


to matplotlib() parameters. By default it is 1.0, which may be undesired.

Also, you may want to draw the figure itself, not by Graphics().save() function. Replace the last line with the following:

from matplotlib.backends.backend_agg import FigureCanvasAgg
2011-12-08 09:28:47 +0200 marked best answer a fast function taking either variable or collection as argument

As for the else statement, this is probably faster:

    return numpy.array([simplefunc(xx) for xx in x])

I probably wouldn't even put that in an else statement either. Just put it as the last line of the function.


It looks like map is slightly faster than a list comprehension in the test below:

sage: def f(x): return x*x
sage: timeit('map(f,xrange(1e6))')
5 loops, best of 3: 223 ms per loop
sage: timeit('[f(x) for x in xrange(1e6)]')
5 loops, best of 3: 277 ms per loop
2011-12-08 06:05:04 +0200 received badge  Scholar (source)