[sage-support] Re: Indexing by elements of a list
Hi dkrumm, On 3 Sep., 09:33, dkrumm dkr...@uga.edu wrote: Is there a data structure in Python that would allow me to do the following: I have a list of positive integer pairs, say [[1,2], [1,3], [2,5]]. For each pair [i,j] in my list I need to store in memory a number c[i,j] Indeed, it is just a Python question. I suggest you read something about Python dictionaries. You could not index a Python dictionary by *lists*, because lists are mutable, and hell breaks if the keys of a dictionary are modified after creation. But they can be indexed by tuples. Hence, you can do: sage: L = [(1,2),(3,4),(5,6)] sage: D = dict(zip(L,range(3))) sage: D {(1, 2): 0, (5, 6): 2, (3, 4): 1} sage: D[3,4] 1 Best regards, Simon -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Indexing by elements of a list
The dictionary is exactly what I needed. Thanks! On Sep 3, 3:56 am, Simon King simon.k...@uni-jena.de wrote: Hi dkrumm, On 3 Sep., 09:33, dkrumm dkr...@uga.edu wrote: Is there a data structure in Python that would allow me to do the following: I have a list of positive integer pairs, say [[1,2], [1,3], [2,5]]. For each pair [i,j] in my list I need to store in memory a number c[i,j] Indeed, it is just a Python question. I suggest you read something about Python dictionaries. You could not index a Python dictionary by *lists*, because lists are mutable, and hell breaks if the keys of a dictionary are modified after creation. But they can be indexed by tuples. Hence, you can do: sage: L = [(1,2),(3,4),(5,6)] sage: D = dict(zip(L,range(3))) sage: D {(1, 2): 0, (5, 6): 2, (3, 4): 1} sage: D[3,4] 1 Best regards, Simon -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Bug in Graph.is_chordal
Hi Nathann, For a time I thought I would be able to patch my proof, but in the end I don't get how this recognition algorithm works... Which is a pity because I am sure I had found a clear explanation in a paper when I implemented all that stuff. What I need right now is some sleep though. Sounds like this will really require a patch :-) I found it quite difficult to find a paper or text which explains the chordless cycle finding. After a long search I got only one (see post #1), but thats probably not the one you are talking about. So the current code with patch #11735 appears to work, but it seems better to patch it, especially since the lexbfs function is also patched ( #11736 http://trac.sagemath.org/sage_trac/ticket/11736 ). As I mentioned, I don't have time to learn the patching process right now, but I made a diff of generic_graph.py in post # 4. I hope it's not so much work to generate a patch from that. I would be very interested if you again find the reference which explains how to find the cycle, it must be really hard to find (or I'm really bad at finding references -_-). Regards, Jan -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] noob q: working directory
On Fri, Sep 2, 2011 at 11:31 PM, Anton Sherwood anton.sherw...@gmail.com wrote: Hi everybody. In the tutorial: Alternatively, evaluating c.save('filename.png') will save the plot to the given file. I tried it, then searched my disk for the relevant filename with no result. Is it a bug? What directory ought it to be in? If you are running sage from the command line, the plot is saved in the same directory you started sage in. (I guess the notebook is similar, but I'm not sure.) You can include a path, along with the filename, if you prefer it to be saved somewhere else. Type c.save? for details. If I try to read in a file, what is the base directory? ... Also: ARGH. Google Groups won't let me register with my preferred address (bro...@pobox.com). -- Anton Sherwood *\\* www.bendwavy.org *\\* www.zazzle.com/tamfang -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Indexing by elements of a list
On 9/3/11 2:33 AM, dkrumm wrote: Is there a data structure in Python that would allow me to do the following: I have a list of positive integer pairs, say [[1,2], [1,3], [2,5]]. For each pair [i,j] in my list I need to store in memory a number c[i,j] which is a floating point number with some large precision. I'd like to create some sort of object M indexed by the elements of my list so that I can refer to M[i,j] and obtain the number c[i,j]. One way (in the example above) would be to create a 5x5 matrix M and only use its entries with indices [1,2], [1,3], and [2,5] to store my numbers. That way I can refer to M[2,5], M[1,2], M[1,3] and get my numbers back. However, this seems like a very inefficient solution (my list is going to be very long, so this matrix M would be huge, and only a few of its entries used). Another way to do it is to use a sparse matrix, which does not store the nonzero entries. Just create the matrix and pass the parameter sparse=True. Or, as Simon suggested, use a dictionary. Storage-wise, there's not a huge amount of difference. In fact, IIRC, sparse matrices are implemented using dictionaries in Sage. Thanks, Jason -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] noob q: working directory
In the tutorial: Alternatively, evaluating c.save('filename.png') will save the plot to the given file. I tried it, then searched my disk for the relevant filename with no result. Is it a bug? What directory ought it to be in? Jason Grout wrote: In the notebook, the graphic would be saved in a temporary directory specific to that cell. The graphic would then be copied to a directory inside the sage notebook directory tree. If you wanted to save it somewhere specific from the notebook, use the full path: c.save('/home/mydir/test.png') Okay, that worked. I'm still curious about the default, tho. In MacOS might it be somewhere within /Applications/Sage-4.7.1-OSX-64bit-10.6.app/ ? or ~/Library/Application Support/ ? -- Anton Sherwood *\\* www.bendwavy.org *\\* www.zazzle.com/tamfang -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: noob q: working directory
On 9/3/11 2:15 PM, Anton Sherwood wrote: In the tutorial: Alternatively, evaluating c.save('filename.png') will save the plot to the given file. I tried it, then searched my disk for the relevant filename with no result. Is it a bug? What directory ought it to be in? Jason Grout wrote: In the notebook, the graphic would be saved in a temporary directory specific to that cell. The graphic would then be copied to a directory inside the sage notebook directory tree. If you wanted to save it somewhere specific from the notebook, use the full path: c.save('/home/mydir/test.png') Okay, that worked. I'm still curious about the default, tho. In MacOS might it be somewhere within /Applications/Sage-4.7.1-OSX-64bit-10.6.app/ ? or ~/Library/Application Support/ ? The graphic eventually would end up in your sage notebook, which would be in ~/.sage/sage_notebook.sagenb/. The temporary directory the graphic originally is in would be something like /tmp/something... You can do: import os print os.getcwd() to see the temp directory for a particular cell. Thanks, Jason -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org