Ask Your Question

npa's profile - activity

2015-10-28 10:38:21 +0200 received badge  Good Question (source)
2015-10-08 15:52:44 +0200 received badge  Famous Question (source)
2014-05-30 06:18:49 +0200 received badge  Notable Question (source)
2013-08-29 12:13:41 +0200 received badge  Famous Question (source)
2013-08-06 07:17:56 +0200 received badge  Popular Question (source)
2013-05-06 04:24:49 +0200 received badge  Notable Question (source)
2013-02-27 11:37:00 +0200 received badge  Popular Question (source)
2012-10-06 21:50:16 +0200 asked a question Is it possible to convert Mathematica notebook to Sage?

I have been using Mathematica, now would like to switch to Sage. Is there a way that I can convert my existing Mathematica notebooks to Sage?

2012-10-06 10:55:30 +0200 received badge  Scholar (source)
2012-10-06 10:55:30 +0200 marked best answer How to plot data from a file?

Suppose that you have a file '/tmp/DataFile' containing the following text

3;2
2;1
1;0.1
0.01;-0.9

Then you can load the two data columns into two arrays xArr and yArr by the following code

f = open('/home/tobi/tmp/DataFile', 'r')

xArr=[]
yArr=[]
line=f.readline()
while(line !=''): 
    xy=line.split(';')
    xArr.append(float(xy[0]))
    yArr.append(float(xy[1]))
    line=f.readline()

Now you can do whatever you want with these array, for example plot them

list_plot(zip(xArr,yArr))

If you like to understand better what open and readline does look at Python doc input output, the split command is explained in the Python doc on strings

2012-10-05 11:20:43 +0200 received badge  Nice Question (source)
2012-10-05 08:06:56 +0200 received badge  Student (source)
2012-10-05 06:28:03 +0200 asked a question How to plot data from a file?

Is it possible to plot data imported from an ASCII file.

2012-10-05 06:14:01 +0200 received badge  Supporter (source)