Ask Your Question

MaelstromYamato's profile - activity

2018-02-03 18:06:06 +0200 received badge  Student (source)
2016-09-25 17:35:39 +0200 received badge  Famous Question (source)
2015-01-23 21:50:55 +0200 received badge  Famous Question (source)
2015-01-06 07:50:39 +0200 received badge  Nice Answer (source)
2014-11-28 20:27:23 +0200 received badge  Notable Question (source)
2013-12-23 12:13:51 +0200 received badge  Notable Question (source)
2013-09-13 15:25:08 +0200 received badge  Famous Question (source)
2013-06-26 09:28:16 +0200 received badge  Popular Question (source)
2013-06-05 10:13:22 +0200 received badge  Popular Question (source)
2013-02-12 15:36:50 +0200 received badge  Notable Question (source)
2012-11-15 03:04:27 +0200 received badge  Popular Question (source)
2012-09-06 14:47:58 +0200 commented answer import sage packages in python

Thanks. This does help!

2012-09-06 14:47:42 +0200 marked best answer import sage packages in python
  1. Matrix -> type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'

    from sage.matrix.all import Matrix

    or

    from sage.matrix.constructor import Matrix

  2. vector -> type 'sage.modules.vector_integer_dense.Vector_integer_dense'

    from sage.modules.free_module_element import vector

  3. ZZ -> type 'sage.rings.integer_ring.IntegerRing_class'

    from sage.rings.integer_ring import ZZ

  4. MixedIntegerLinearProgram -> type 'sage.numerical.mip.MixedIntegerLinearProgram'

    from sage.numerical.mip import MixedIntegerLinearProgram

Once you know roughly where the class is defined, for example Matrix is defined somewhere in SAGE_ROOT/devel/sage/sage/matrix/, take a look at the file all.py in that directory. In this case you'll find a line

from constructor import matrix, Matrix, column_matrix, random_matrix, diagonal_matrix, identity_matrix, block_matrix, block_diagonal_matrix, jordan_block, zero_matrix, ones_matrix, elementary_matrix, companion_matrix

So that tells you that you can import Matrix from sage.matrix.all or from sage.matrix.constructor. Your other examples can be dealt with similarly.

2012-09-06 13:35:55 +0200 answered a question Can I use amsmath in notebook?

Try the following in a notebook:

from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amsmath}')
latex.add_to_preamble('\\usepackage{amsthm}')
latex.add_to_preamble('\\usepackage{amssymb}')
2012-09-06 13:32:39 +0200 commented answer Graphs from inside a function

you can use show(), save('/my/favorite/folder/for/graphs/graph1.png'), return graph object from the function and have another function show it.

2012-09-06 13:29:57 +0200 asked a question import sage packages in python

An easy way to use sage in python files is demonstrated in the Sage Tutorial.

#!/usr/bin/env sage -python

import sys
from sage.all import *

if len(sys.argv) != 2:
    print "Usage: %s <n>"%sys.argv[0]
    print "Outputs the prime factorization of n."
    sys.exit(1)

print factor(sage_eval(sys.argv[1]))

Well, what if I don't want to import all of sage as shown above using:

from sage.all import *

Instead of this command above, I just want to import the following:

  1. Matrix -> type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'
  2. vector -> type 'sage.modules.vector_integer_dense.Vector_integer_dense'
  3. ZZ -> type 'sage.rings.integer_ring.IntegerRing_class'
  4. MixedIntegerLinearProgram -> type 'sage.numerical.mip.MixedIntegerLinearProgram'

So I should be able to write something like this in python

from sage.library.package.for.Matrix import *
from sage.library.package.for.vector import *
from sage.library.package.for.ZZ import *
from sage.library.package.for.MixedIntegerLinearProgram import *

I just don't know what they are. Any help is appreciated.

Thanks.

2012-07-03 18:19:51 +0200 commented answer TypeError: 'int' object is not iterable

Oh boy... I feel silly how that stumped me all day long. Thank you!

2012-07-03 18:19:08 +0200 marked best answer TypeError: 'int' object is not iterable

The problem is in the line

dict = {j:Set(int(Vec[i]))}

The Set constructor takes an iterable object and the python int type is not iterable. If you change the line to:

dict = {j:Set( [int(Vec[i])] )}

that problem should go away.

2012-07-03 13:03:11 +0200 asked a question TypeError: 'int' object is not iterable

Hello,

For a given matrix M (m by n) and vector V of size n, my goal is to do the following:

  1. Take the $\text{i}^{\text{th}}$ column of M and convert them as keywords for a dictionary and associate the keywords to the $\text{i}^{\text{th}}$ value of the vector V.
    1. I do (1) in MatVec(M,V) in the code below by creating a dictionary for each keyword and value. Finally I try to merge all the dictionaries.

Here is my code:

def DictionaryMerge(*args):
    import collections
    super_dict = collections.defaultdict(set)
    for d in args:
        for k, v in d.iteritmes():
            super_dict[k].add(v)
    return super_dict

def MatVec(M,V):
    from sets import Set
    Vec = V.list()
    MatCols = M.ncols()
    D2 = {}
    for i in range(MatCols):
        ColumnVec = M.column(i).list()
        CVec = list()
        for k in range(len(ColumnVec)):
            CVec.append(int(ColumnVec[k]))
        for j in CVec:
            dict = {j:Set(int(Vec[i]))}
            D2 = DictionaryMerge(dict,D2)
     return dict

M = matrix([[(i+1)*(j+2) for i in range(5)] for j in range(6)])
V = vector([int(i+100) for i in range(5)])
MatVec(M,V)

The error I get is:

Traceback (most recent call last):        return super_dict
  File "", line 1, in <module>

  File "/tmp/tmp4m6HiR/___code___.py", line 29, in <module>
     exec compile(u'MatVec(M,V)
  File "", line 1, in <module>

  File "/tmp/tmp4m6HiR/___code___.py", line 22, in MatVec
     dict = {j:Set(int(Vec[i]))}
  File "/home/usr111/sage/local/lib/python/sets.py", line 414, in __init__
     self._update(iterable)
  File "/home/usr111/sage/local/lib/python/sets.py", line 368, in _update
     for element in iterable:
 TypeError: 'int' object is not iterable

I am not so sure why I am getting this error.

2012-07-03 12:11:51 +0200 answered a question Emacs IPython Notebook

perhaps someone can forward this to the sage trac or provide it a tracking number (if the idea has not been considered already).

2012-06-25 13:26:23 +0200 received badge  Nice Answer (source)
2012-06-22 15:35:03 +0200 received badge  Teacher (source)
2012-06-22 15:35:03 +0200 received badge  Necromancer (source)
2012-06-20 14:46:13 +0200 answered a question "code for hash md5 was not found" after fresh Sage 5.0 install on fresh Ubuntu 12.04 install

Try installing libssl0.9.8. e.g.:

sudo apt-get install libssl0.9.8

I got a similar error before installing the library above:

----------------------------------------------------------------------
| Sage Version 5.0.1, Release Date: 2012-06-10                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------
The Sage installation tree may have moved
(from /scratch/buildbot/sage/redhawk-1/redhawk_binary/build/sage-5.0.1 to /home/clinton/sage).
Changing various hardcoded paths...
(Please wait at most a few minutes.)
DO NOT INTERRUPT THIS.
Done resetting paths.
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 139, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/home/clinton/sage/local/lib/python/hashlib.py", line 91, in __get_builtin_constructor
    raise ValueError('unsupported hash type %s' % name)
ValueError: unsupported hash type sha512
Traceback (most recent call last):
  File "/home/clinton/sage/local/bin/sage-ipython", line 18, in <module>
    import IPython
  File "/home/clinton/sage/local/lib/python2.7/site-packages/IPython/__init__.py", line 58, in <module>
    __import__(name,glob,loc,[])
  File "/home/clinton/sage/local/lib/python2.7/site-packages/IPython/ipstruct.py", line 17, in <module>
    from IPython.genutils import list2dict2
  File "/home/clinton/sage/local/lib/python2.7/site-packages/IPython/genutils.py", line 53, in <module>
    from IPython.external.path import path
  File "/home/clinton/sage ...
(more)
2012-05-29 10:57:24 +0200 commented answer How to find the path of the maximal distance between two vertices on a complete digraph?

That was a wonderful explanation of the solution. Thank you!!!

2012-05-29 10:56:52 +0200 marked best answer How to find the path of the maximal distance between two vertices on a complete digraph?

One way to do the general case uses the all_paths method:

sage: [path for path in g.all_paths(0,1) if len(path) == 5]
[[0, 2, 3, 4, 1], [0, 2, 4, 3, 1], [0, 3, 2, 4, 1], [0, 3, 4, 2, 1], [0, 4, 2, 3, 1], [0, 4, 3, 2, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 4]
[[0, 2, 3, 1], [0, 2, 4, 1], [0, 3, 2, 1], [0, 3, 4, 1], [0, 4, 2, 1], [0, 4, 3, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 3]
[[0, 2, 1], [0, 3, 1], [0, 4, 1]]
sage: [path for path in g.all_paths(0,1) if len(path) == 2]
[[0, 1]]

There is also a longest_path method that takes source and destination as input parameters, but there seems to be a bug with directed graphs. I've made this #13019.

At the theoretical level, the problem is really easy for this specific graph since there are edges between all the vertices. Thus, you can just pick the endpoints and take any permutation of the remaining vertices (or subset of them) to get a path of a fixed length.

2012-05-29 10:56:52 +0200 received badge  Scholar (source)
2012-05-29 10:56:51 +0200 received badge  Supporter (source)
2012-05-25 16:27:40 +0200 commented question How to find the path of the maximal distance between two vertices on a complete digraph?

In general, I would also like to find if the complete digraph has n vertices, how can I find the path(s) from any two vertices of distance (n-1), (n-2), ..., 2?

2012-05-25 15:35:07 +0200 received badge  Editor (source)
2012-05-25 15:29:27 +0200 answered a question How to install sage5 in OpenSuSE 11.4

Have you tried building from source?

If you need help installing the necessary packages to make sage, review the packages you'll need in SUSE from the debian repositories for build-essential, m4, and gfortran

2012-05-25 14:06:58 +0200 asked a question How to find the path of the maximal distance between two vertices on a complete digraph?

I was wondering how can I find the path of the maximal distance between two vertices on a complete digraph. Suppose the digraph has 5 vertices:

sage: g = graphs.CompleteGraph(5).to_directed()

I have seen a maximal flow example which is nice but it is not the same type of problem. How can I use sage to find the longest path?

2011-08-16 10:45:55 +0200 answered a question Why does Sage not install with Vista?

did you mean this link: "http://localhost:8000 "?

At which step are you stuck on in the "http://www.sagemath.org/mirror/win/README.txt"?