Ask Your Question

al's profile - activity

2018-11-19 18:55:41 -0500 asked a question Question (and answer) about deepcopy in Sage

This was driving me crazy but I just found the answer, slightly different from what I found in a link below. I will explain. I hope it may be useful to other beginners!

If you have a list of numbers and want to change one, but save the old list, no problem; you can use = as follows:

T=[1,2,3]

S=T

S[0]=5

now you find that S= [5,2,3] while T= [1,2,3]

If you do this with a list of lists, changing T changes S also, as they are identified. The way to solve this is with the copy command, either

S=T[:]

or

S=copy(T).

However, if T is a list of lists of lists, which is very easy to come across, you are in trouble. There is a Python command called "deepcopy" which deals with this.

See https://stackoverflow.com/questions/2...

The point I just discovered is that to use this instead of e.g. S=copy.deepcopy(T) as suggested in the link -- this gave me an error message!!! --maybe it's ok in Pythin?? what works in SAGEMATH is simply S=deepcopy(T).

example:

T=[] S=[]

T=[[1],[2],[3]]

S=T[:]

(or equivalently S=copy(T) )

then if you do

S[0][0]=5

now both S and T are [[5],[2],[3]].

if instead you do

S= deepcopy(T)

as suggested by the links (slight modification) then this works!!! The explanation for why is in the links.

2018-11-18 14:10:45 -0500 received badge  Self-Learner (source)
2018-11-18 14:10:45 -0500 received badge  Teacher (source)
2018-11-18 10:05:50 -0500 answered a question question about Python assignment of lists; meaning of equals sign; how to save a list?

I think I just found what the problem is: "This is really a matter of how Python handles assignments of lists."

Here is the solution:

sage: L1 = [1, 2]
sage: L2 = [3, 4]
sage: L1
[1, 2]
sage: L2
[3, 4]
sage: L1.extend(L2)
sage: L1
[1, 2, 3, 4]
sage: L2
[3, 4]
sage: L3 = L1[:]
sage: L3
[1, 2, 3, 4]
sage: L1.append(8)
sage: L1
[1, 2, 3, 4, 8]
sage: L3
[1, 2, 3, 4]

I found the explanation in @calc314's answer to Ask Sage question 25998 by @ikol.

2018-11-18 08:59:29 -0500 asked a question question about Python assignment of lists; meaning of equals sign; how to save a list?

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

sage: L1 = [1, 2]
sage: L2 = [3, 4]
sage: L3 = L1
sage: L1
[1, 2]
sage: L2
[3, 4]
sage: L3
[1, 2]
sage: L1.extend(L2)
sage: L1
[1, 2, 3, 4]
sage: L2
[3, 4]
sage: L3
[1, 2, 3, 4]

The same thing happens with "append".

Help please!!!

Note: this does not happen with variables with numerical (not list) values. For example:

sage: a = 4
sage: b = a
sage: a = 5
sage: a
5
sage: b
4

So it seems that the equals sign means two different things: for numbers it is an assignment; for lists it is an identification. This is driving me crazy. I cannot find it explained anywhere (maybe because it is so "well-known"?)

2018-03-27 14:28:59 -0500 received badge  Notable Question (source)
2018-02-07 14:35:32 -0500 commented answer How do you get a 2d version of a 3d plot?

how0 b = show0(a) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2625, in show0 salvus.threed(obj, **kwds) TypeError: threed() got an unexpected keyword argument 'viewer'

2018-02-07 14:35:23 -0500 commented answer How do you get a 2d version of a 3d plot?

I am actually using three.js (it says "canvas" below the plot). I tried Tachyon and got an image of much worse quality, and tried jmol but got an error message: Error in lines 76-76 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1013, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "sage/plot/plot3d/base.pyx", line 1478, in sage.plot.plot3d.base.Graphics3d.show (build/cythonized/sage/plot/plot3d/base.c:21473) dm.display_immediately(self, **kwds) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2678, in show s = show0(objs, combine_all=True) File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_salvus.py", line 2639, in s

2018-02-03 18:36:01 -0500 commented question Notebook problems

Yes, I use /Applications/SageMath-7.2.app/Contents/Resources/sage/sage; exit then notebook()

Not sure how to test what you suggest, can you be more explicit? Thanks !!

2018-02-03 07:16:47 -0500 answered a question Save 3d plot as vector format

I had the same question. The screen capture suggested by calc314 worked fine, thank you! But I wonder how much quality is lost, and whether a more direct output to pdf wouldn't be better. I tried Tachyon but the result was much worse- axes had been shifted, a transparent surface had disappeared....!!!

In fact, when people illustrate textbooks, do they sometimes use Sagemath, or do they always switch to Mathematica or Maple or something partly because of this issue ?

2018-02-02 15:09:34 -0500 commented question Notebook problems

Morecomments: In answer to the comment: I have SAGE 7.2 installed on my mac with OSX 10.10.5. It opens in the Firefox browser. To install it I downloaded the Mac OSX binaries fior which it says Download Mac OS X binaries "These binaries are only for OS X 10.4 - 10.10. " from this page: http://www.sagemath.org/download.html

I am using the Sage notebook. There is no error message- it just doesn't work anymore, as described above. The "Discard and Quit" and Delete" buttons also don't work. If I open a file, it is marked (running) but Stpo doesn't stop it. To stop it, I can logout, then I start sage from terminal, kill the old PID, type notebook() and I see all the files, none are running.

2018-02-02 14:59:06 -0500 commented question Sage notebook frozen

In answer to the comment: I have SAGE 7.2 installed on my mac with OSX 10.10.5. It opens in the Firefox browser. To install it I downloaded the Mac OSX binaries fior which it says Download Mac OS X binaries "These binaries are only for OS X 10.4 - 10.10. " from this page: http://www.sagemath.org/download.html

I am using the Sage notebook. There is no error message- it just doesn't work anymore, as described above. The "Discard and Quit" and Delete" buttons also don't work. If I open a file, it is marked (running) but Stpo doesn't stop it. To stop it, I can logout, then I start sage from terminal, kill the old PID, type notebook() and I see all the files, none are running.

2018-02-02 14:26:19 -0500 commented question Sagemath notebook stopped working

In answer to the first comment: I have SAGE 7.2 installed on my mac with OSX 10.10.5. It opens in the Firefox browser. To install it I downloaded the Mac OSX binaries fior which it says
Download Mac OS X binaries "These binaries are only for OS X 10.4 - 10.10. " from this page: http://www.sagemath.org/download.html

2018-02-02 14:16:49 -0500 commented question Sage notebook frozen

Thanks Thierry I'll check on it and try to reply.

2018-02-02 14:15:47 -0500 commented question Sagemath notebook stopped working

Thanks for your comments, I'll work on those and reply.

2018-02-02 14:13:09 -0500 asked a question Notebook problems

I am asking this for the third time with more details, since there are no answers yet. Since my notebook isn't working, I am using the Cloud, but I'd like to get the notebook running again.

So, I have sagemath notebook installed on my Mac laptop, and it has been working fine until recently, maybe because I tried to run some 3d graphics program I found on the Sagemath manual. Then it froze up.

I can see all my files, but I cannot run any programs. There is no "evaluate" button. The box for a new program doesn't turn blue around the edge. If I open up a worksheet, and go back to the list of files, it says (running), though nothing is working. Also, the "Help" and "Report a Problem" and "log" buttons don't work. "Home" and "Sign Out" do.

I can sign out, log back in and it's still stuck. Restarting the Mac also doesn't help. Do I have to create a new notebook? Reinstall everything?

Help please !!!

thanks very much

2018-02-02 05:22:53 -0500 commented answer How to save a 3d plot from sage cell

Very interesting answers. Now the issue I have is how to get the 3d capability on the notebook on my computer- any hints? It runs in the cloud but not on my own notebook version so far.

2018-02-02 05:20:37 -0500 commented answer How to save graphics into an image in sagemath online?

I had the same question and tried this. It worked (sort of) but the resulting image had been changed in strange ways, and also there is no option to rotate/zoom to the view you want. The picture I got from screenshot was much better quality. It's hard to believe this is not built into Sagemath- how does anyone use Sagemath for making high-quality illustrations for a paper or a book?

2018-02-01 08:16:06 -0500 asked a question How do you get a 2d version of a 3d plot?

I am working on Cocalc. I would like to get a nice pdf of the view I want after rotating and zooming. Yes, taking a screenshot works, but is there a better method? Thanks !

2018-01-29 13:17:59 -0500 received badge  Commentator
2018-01-29 13:17:59 -0500 commented answer How can you change the viewpoint of perspective (to infinity) in a 3d plot?

In fact, what I just noticed is that the viewpoint changes as you zoom in. So when you zoom out, say of a cube, it will approach what I want (orthographic projection) as the viewpoint approaches infinity. As you zoom close, you see two nested squares connected by edges, with the back face much smaller as you get close. The problem now is that when I zoom away, the figure itself is getting too small !

2018-01-29 12:44:36 -0500 commented answer How can you change the viewpoint of perspective (to infinity) in a 3d plot?

Ooops, in fact what I want is apparently called "orthographic projection", not isometric ! Any ideas?

2018-01-29 12:39:54 -0500 commented answer How can you change the viewpoint of perspective (to infinity) in a 3d plot?

Thanks for the answer! I am using the Cloud with the command show(list_plot3d,(x,-2,2),(y,-2,2),aspect_ratio = [1,1,1]) However would rather run this on my notebook (once my notebook is running again- see my other question !) Could you give me some hints as to how to get 3d plots working on the notebook- which other software should I to add to the basic SAGEmath installation? And is there good information available on this?

(and do you recommend jsmol/jmol for mathematics graphics? )

2018-01-29 04:43:53 -0500 asked a question How can you change the viewpoint of perspective (to infinity) in a 3d plot?

I am plotting a function with a large z coordinate, so it has a rectangular solid box around it which is square in crossection and very long in height. If you rotate it to view from the end you don't see the orthogonal projection onto the square, since the solid framing the graph is rendered inperspective from a viewpoint which is not infinity. I tried aspect_ration {1,1,1] but that doesn't correct it. Any ideas ???

PS I'm running this ion the Cloud - I can't get 3d plots to run in my own notebook yet, and anyway right now my notebook isn't working at all- see other question !

2018-01-29 03:54:15 -0500 asked a question Sagemath notebook stopped working

Sorry, I'm re-asking this question as there are not yet any responses....Notebook was working just fine. Then suddenly, it stopped working and nothing I try helps. You can type or copy and paste into the cell, but it remains as a box only one line high. Cell doesn't have heavy blue line around it; there is no "evaluate" button and shift-return doesn't run it. I tried killing Sagemath from the terminal by killing the PID, and restarting from the terminal; I tried clearing the Firefox cache; repairing disk permissions; restarting mac. Nothing works !!! HELP please !!!

2018-01-28 08:29:49 -0500 received badge  Editor (source)
2018-01-28 08:25:21 -0500 asked a question Sage notebook frozen

Notebook was working fine. Then suddenly, it stopped working and nothing I try helps. You can type or copy and paste into the cell, but it remains as a box only one line high. Cell doesn't have heavy blue line around it; there is no "evaluate" button and shift-return doesn't run it. I tried killing Sagemath from the terminal by killing the PID, and restarting from the terminal; I tried clearing the Firefox cache; repairing disk permissions; restarting mac. Nothing works !!! HELP please !!!

2017-09-25 10:42:07 -0500 received badge  Popular Question (source)
2017-06-24 00:34:52 -0500 commented question Error importing scipy for SAGE notebook

PS I just tried changing the line "import scipy" to "import numpy" and get a long error message finishing the same way, with: ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python intepreter.

2017-06-24 00:33:15 -0500 commented question Error importing scipy for SAGE notebook

File "/private/var/folders/18/gmqqrhkd1wb4l1pv6sldfr5r0000gp/T/tmp9VOZ6s/___code___.py", line 3, in <module> import scipy File "/Applications/SageMath-7.2.app/Contents/Resources/sage/local/lib/python2.7/site-packages/scipy/__init__.py", line 103, in <module> raise ImportError(msg) ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python intepreter.

Any ideas?? Thanks!

2017-06-24 00:32:42 -0500 commented question Error importing scipy for SAGE notebook

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_17.py", line 10, in <module> exec compile(u'open("___code___.py","w").write("# -- coding: utf-8 --\n" + _support_.preparse_worksheet_cell(base64.b64decode("aW1wb3J0IHNjaXB5CngsIHkgPSB2YXIoJ3ggeScpClcgPSBwbG90M2Qoc2luKHBpKigoeCleMisoeSleMikpLzIsKHgsLTEsMSksKHksLTEsMSksIGZyYW1lPUZhbHNlLCBjb2xvcj0ncHVycGxlJywgb3BhY2l0eT0wLjgpClMgPSBzcGhlcmUoKDAsMCwwKSxzaXplPTAuMywgY29sb3I9J3JlZCcsIGFzcGVjdF9yYXRpbz1bMSwxLDFdKQpzaG93KFcgKyBTLCBmaWdzaXplPTgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in <module>

2017-06-24 00:30:14 -0500 commented question Error importing scipy for SAGE notebook

Hi kcrisman- I finally got back to this issue and am trying to resolve it. The problem is that for some reason I can't get 3d graphics to work in my sage notebook. I thought scipy would be part of the sagemath package 7.2, so am surprised it may need to be installed. In any case, just saw your suggestion of trying to do "import scipy" so I added it to a program found on the web, which runs fine in sage cell. Here is the result.

import scipy x, y = var('x y') W = plot3d(sin(pi*((x)^2+(y)^2))/2,(x,-1,1),(y,-1,1), frame=False, color='purple', opacity=0.8) S = sphere((0,0,0),size=0.3, color='red', aspect_ratio=[1,1,1]) show(W + S, figsize=8)

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_17 ... (more)