File: read_array_demo1.py

package info (click to toggle)
python-scipy 0.6.0-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 32,016 kB
  • ctags: 46,675
  • sloc: cpp: 124,854; ansic: 110,614; python: 108,664; fortran: 76,260; objc: 424; makefile: 384; sh: 10
file content (58 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#=========================================================================
# NAME: read_array_demo1
#
# DESCRIPTION: Examples to read 2 columns from a multicolumn ascii text 
# file, skipping the first line of header. First example reads into 
# 2 separate arrays. Second example reads into a single array. Data are
# then plotted.
#
# Here is the format of the file test.txt:
# --------
# Some header to skip
# 1 2 3
# 2 4 6
# 3 6 9
# 4 8 12
#
# USAGE:
# python read_array_demo1.py
#       
# PARAMETERS:
#
# DEPENDENCIES:
# matplotlib (pylab)
# test.txt
#
#
# AUTHOR: Simon J. Hook
# DATE  : 09/23/2005
#
# MODIFICATION HISTORY:
#
# COMMENT:
#
#============================================================================

from scipy import *
from scipy.io import read_array
from pylab import *

def main():

    # First example, read first and second column from ascii file. Skip first
    # line of header.
    # Note use of (1,-1) in lines to skip first line and then read to end of file
    # Note use of (0,) in columns to pick first column, since its a tuple need trailing comma
    x=read_array("test.txt",lines=(1,-1), columns=(0,))
    y=read_array("test.txt",lines=(1,-1), columns=(1,))

    #Second example, read the file into a single arry
    z=read_array("test.txt",lines=(1,-1), columns=(0,2))
    
    # Plot the data
    plot(x,y,'r--',z[:,0],z[:,1])
    show()

# The one and only main function
if __name__ == "__main__":
    main()