Results 1 to 3 of 3

Thread: Saving mixed data in scientific python

  1. #1
    Join Date
    Nov 2006
    Location
    Swansea, Wales
    Beans
    59
    Distro
    Ubuntu

    Saving mixed data in scientific python

    Hi,

    So I've recently moved away from using matlab to use scientific python using predominantly pylab, numpy and scipy. I am however having difficultie in saving a mixed data format of the following structure:

    # Header 1
    # Header 2
    x(1) y(1) z(1)
    . . .
    . . .
    . . .
    x(N) y(N) z(N)

    I can save the header files quite easily using the following:
    Code:
    f=open('myfile.txt','w')
    f.write('#Header1\n#Header2)
    f.close
    When I more myfile.txt I get
    #Header1
    #Header2


    The difficultie I'm having is storing the array below the header. The x,y,z data is stored as a numpy.ndarray called XYZ. I have tried pickling the data but I must admit I'm not sure what I'm doing.

    Can any of you guys help? Are there any numpy/scipy modules I can use?

    Cheers

  2. #2
    Join Date
    Jul 2008
    Location
    Bracknell, England
    Beans
    87
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Saving mixed data in scientific python

    Glenn,

    I don't know scientific python/Pylab etc but the write statement you have in normal python will only write what you are getting.

    You may try:


    Code:
    f=open('myfile.txt','w')
    f.write('#Header1\n#Header2)
    f.write(XYZ)
    f.close
    and see if the output is useful to you. Other wise if nobody can find a library routine to help you may have to iterate through the array with for statements and write each element individually.

    Hope this helps,

    Steve

  3. #3
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,082
    Distro
    Ubuntu Studio 13.04 Raring Ringtail

    Re: Saving mixed data in scientific python

    there are some examples at http://www.scipy.org/Cookbook/InputOutput that may help you.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •