ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Nov 2013 06:59:04 -0600How to input data in SAGE and deal with themhttps://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/I wish to calculate the width of the certain polytopes, the data for these polytopes can be found [here](http://hep.itp.tuwien.ac.at/~kreuzer/CY/) (please click "K3/3d" on the left, and then click "list of all 4319" on the top of new page, for some reason, I could not cite the exact URL).
For example, the first one is
3 4 M:5 4 N:35 4 Pic:19 Cor:0
1 0 0 -1
0 1 0 -1
0 0 1 -1
However, only the number in the matrix will be used in the calculation. My questions are:
(1) How to input these data in SAGE (I use a windows system, and run Virtualbox for SAGE)?
(2) How to use sage to deal with each matrix?
For each of matrix, I have a program as the follows
sage: m = matrix(ZZ, [[1,0,0,-1],
....: [0,1,0,-1],
....: [0,0,1,-1]])
sage: p = LatticePolytope(m)
sage: d = p.distances()
sage: l = p.nfacets()
sage: for i in range(l):
....: max(d.row(i))
After input the data, how to let sage use the same program deal with each matrix?
Thank you very much for your help!!!Sat, 02 Nov 2013 15:20:45 -0500https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/Comment by twch for <p>I wish to calculate the width of the certain polytopes, the data for these polytopes can be found <a href="http://hep.itp.tuwien.ac.at/~kreuzer/CY/">here</a> (please click "K3/3d" on the left, and then click "list of all 4319" on the top of new page, for some reason, I could not cite the exact URL).</p>
<p>For example, the first one is </p>
<p>3 4 M:5 4 N:35 4 Pic:19 Cor:0</p>
<pre><code>1 0 0 -1
0 1 0 -1
0 0 1 -1
</code></pre>
<p>However, only the number in the matrix will be used in the calculation. My questions are:</p>
<p>(1) How to input these data in SAGE (I use a windows system, and run Virtualbox for SAGE)?</p>
<p>(2) How to use sage to deal with each matrix? </p>
<p>For each of matrix, I have a program as the follows</p>
<pre><code>sage: m = matrix(ZZ, [[1,0,0,-1],
....: [0,1,0,-1],
....: [0,0,1,-1]])
sage: p = LatticePolytope(m)
sage: d = p.distances()
sage: l = p.nfacets()
sage: for i in range(l):
....: max(d.row(i))
</code></pre>
<p>After input the data, how to let sage use the same program deal with each matrix?</p>
<p>Thank you very much for your help!!!</p>
https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?comment=16810#post-id-16810Maybe also the answers in this (http://ask.sagemath.org/question/1842/how-to-plot-data-from-a-file#2705) related questions are helpful.Sun, 03 Nov 2013 04:23:21 -0600https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?comment=16810#post-id-16810Answer by ndomes for <p>I wish to calculate the width of the certain polytopes, the data for these polytopes can be found <a href="http://hep.itp.tuwien.ac.at/~kreuzer/CY/">here</a> (please click "K3/3d" on the left, and then click "list of all 4319" on the top of new page, for some reason, I could not cite the exact URL).</p>
<p>For example, the first one is </p>
<p>3 4 M:5 4 N:35 4 Pic:19 Cor:0</p>
<pre><code>1 0 0 -1
0 1 0 -1
0 0 1 -1
</code></pre>
<p>However, only the number in the matrix will be used in the calculation. My questions are:</p>
<p>(1) How to input these data in SAGE (I use a windows system, and run Virtualbox for SAGE)?</p>
<p>(2) How to use sage to deal with each matrix? </p>
<p>For each of matrix, I have a program as the follows</p>
<pre><code>sage: m = matrix(ZZ, [[1,0,0,-1],
....: [0,1,0,-1],
....: [0,0,1,-1]])
sage: p = LatticePolytope(m)
sage: d = p.distances()
sage: l = p.nfacets()
sage: for i in range(l):
....: max(d.row(i))
</code></pre>
<p>After input the data, how to let sage use the same program deal with each matrix?</p>
<p>Thank you very much for your help!!!</p>
https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?answer=15644#post-id-15644Copy and paste the data from "K3/3d" to a text file.
Upload that file to your worksheet (I use Sage Notebook).
(I name the file 'k3_d3_data.txt')
Open the file in your worksheet. Now you can iterate through the lines and convert the appropriate lines to matrices.
data_file = file(DATA+'k3_d3_data.txt','r')
matrix_list = []
while True:
try:
data_file.next()
except StopIteration:
break
row1 = [int(z) for z in data_file.next().split()]
row2 = [int(z) for z in data_file.next().split()]
row3 = [int(z) for z in data_file.next().split()]
matrix_list.append(matrix(ZZ,[row1,row2,row3]))
for M in matrix_list:
print M Sat, 02 Nov 2013 21:25:13 -0500https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?answer=15644#post-id-15644Comment by Li Yutong for <p>Copy and paste the data from "K3/3d" to a text file.
Upload that file to your worksheet (I use Sage Notebook).
(I name the file 'k3_d3_data.txt')</p>
<p>Open the file in your worksheet. Now you can iterate through the lines and convert the appropriate lines to matrices.</p>
<pre><code>data_file = file(DATA+'k3_d3_data.txt','r')
matrix_list = []
while True:
try:
data_file.next()
except StopIteration:
break
row1 = [int(z) for z in data_file.next().split()]
row2 = [int(z) for z in data_file.next().split()]
row3 = [int(z) for z in data_file.next().split()]
matrix_list.append(matrix(ZZ,[row1,row2,row3]))
for M in matrix_list:
print M
</code></pre>
https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?comment=16809#post-id-16809@ndomes, Thank you very very much!!! You answer is fabulous, I know how to do it now!!!Sun, 03 Nov 2013 06:59:04 -0600https://ask.sagemath.org/question/10686/how-to-input-data-in-sage-and-deal-with-them/?comment=16809#post-id-16809