Ask Your Question
1

It is possible to use a previous output?

asked 2020-04-23 16:19:00 +0200

Masacroso gravatar image

updated 2020-04-23 16:21:57 +0200

I dont find anything in the documentation about the possibility to re-use previous outputs, in jupyter notebook or in the prompt, so I will ask here: there is a command to reuse a previous output instead to avoid recompute it again?

By example, say that I compute a value of a function and I want to re-use again this result, there is a way to call for the oputput instead of re-computing it value again or pre-assigning the value to a variable? Of course a solution could be just copy-and-paste the output, by I want to know if there is a command to avoid also this manipulation.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
4

answered 2020-04-23 17:25:46 +0200

Sébastien gravatar image

updated 2020-04-23 17:37:51 +0200

SageMath command line and Jupyter notebook are both based on ipython. As described in the section Output caching system of the documention of ipython, the underscore _ stores the previous result. The double underscore __ stores the pre-previous and triple underscore ___ stores the pre-pre-previous:

sage: 10 * 10
100
sage: _ + 1
101
sage: __ + 3
103
sage: ___ + 5
105

You may also use the list Out which stores all of the results:

sage: Out
{1: 100, 2: 101, 3: 103, 4: 105}

or _<n> where n the n-th output from the start:

sage: _3
103
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-23 16:19:00 +0200

Seen: 1,157 times

Last updated: Apr 23 '20