Re: maximum value in a column of file



thank you for your answer
actually i've to do some statistics (maximum,minimum,mean,standard
deviation,....) of a file of data in which each column is a particular
type of data. (the file is a tab separated value).
I was trying to do this by using python (usually i work with fortran or
bash, but i'm learning python), that the reason why i tried to use numpy.

numpy.loadtxt is probably what your looking for, provided your file
contains only numbers and comment lines.
check the example here: http://www.scipy.org/Numpy_Example_List_With_Doc#head-88ade192dacf0c15e4f1377096134ee559df07a0

X = numpy.loadtxt('data.txt')
X[:,0].mean() # mean of first column
X[:,0].max() # mux of first column
X[:,0].var() # variance of first column
....

enjoy! bernhard



As I implied, you can do all this in standard Python "by hand", but
numpy/scipy can definitely make things easier. There's a dependency
cost here (your program needs one or more extra libraries to work), but
if that's no problem in your environment, I'd recommend that approach.

The scipy add-on contains a bunch of things for file i/o; see

http://www.scipy.org/doc/api_docs/SciPy.io.html

for an overview. Since you're reading text files, the "array_import"
module seems to be what you need:

http://www.scipy.org/doc/api_docs/SciPy.io.array_import.html

There are active user communities for both numpy and scipy that can help
you sort out any remaining issues; for details, see:

http://www.scipy.org/Mailing_Lists

Hope this helps!

</F>

.



Relevant Pages

  • Re: Reading Fortran Data
    ... am currently getting acquainted with Python and, in particular SciPy, ... NumPy, and Matplotlib. ... Fortran. ... this in Python is to use string formating with a given width. ...
    (comp.lang.python)
  • Re: Re: maximum value in a column of file
    ... I was trying to do this by using python, that the reason why i tried to use numpy. ... extract value from line ... ...
    (comp.lang.python)
  • Re: switching to numpy and failing, a user story
    ... switch a large codebase (python and C++) to using numpy. ... numpy/scipy mailing lists (else you used a different name or email, ...
    (comp.lang.python)
  • Re: memory leak problem with arrays
    ... I'm new to programming in python and I hope that this is the problem. ... I've created a cellular automata program in python with the numpy array ... Python keeps track of number of references to every object if the ... Sent message to the NumPy forum as per Roberts suggestion. ...
    (comp.lang.python)
  • Re: Atlas and NumPy Problems
    ... Robert Kern wrote: ... In installing NumPy, I ... It worked fine on my machine because I had modified my Python config to ...
    (comp.lang.python)