Formatting arrays using myarrayy.tolist()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Max Abrahams

    Formatting arrays using myarrayy.tolist()

    I've got an array that looks like this:

    >>p.xv[20:25]
    array([[ 1.60783821e-01, 1.04174046e+01, -1.74045566e-03,
    6.02421398e-01, 2.16078382e+00, -1.60783821e-02],
    [ 1.66704816e-01, 1.04390422e+01, -1.90421758e-03,
    5.81767402e-01, 2.16670482e+00, -1.66704816e-02],
    [ 1.72418976e-01, 1.04607380e+01, -2.07379715e-03,
    5.61054649e-01, 2.17241898e+00, -1.72418976e-02],
    [ 1.77925722e-01, 1.04824899e+01, -2.24898715e-03,
    5.40285230e-01, 2.17792572e+00, -1.77925722e-02],
    [ 1.83224500e-01, 1.05042958e+01, -2.42957975e-03,
    5.19461244e-01, 2.18322450e+00, -1.83224500e-02]])

    I want to dump it to a plain text file. The problem is, it unravels
    the array. The text file will look like this

    p.xv.tofile('fi le','\n')


    10.3528613872
    -0.0012861387218 8
    0.664009998909
    2.14178590964
    -0.0141785909637
    0.148323738585
    10.3743121062
    -0.0014312106189

    and so on.
    i want it to look like this:

    1 2 3 4 5 6
    7 8 9 10 11 12
    13 14 15 16 17 18
    19 20 21 22 23 24


    any help would be appreciated.
    thanks.
  • Colin J. Williams

    #2
    Re: Formatting arrays using myarrayy.tolist ()

    Max Abrahams wrote:
    I've got an array that looks like this:
    >
    >
    >p.xv[20:25]
    >
    array([[ 1.60783821e-01, 1.04174046e+01, -1.74045566e-03,
    6.02421398e-01, 2.16078382e+00, -1.60783821e-02],
    [ 1.66704816e-01, 1.04390422e+01, -1.90421758e-03,
    5.81767402e-01, 2.16670482e+00, -1.66704816e-02],
    [ 1.72418976e-01, 1.04607380e+01, -2.07379715e-03,
    5.61054649e-01, 2.17241898e+00, -1.72418976e-02],
    [ 1.77925722e-01, 1.04824899e+01, -2.24898715e-03,
    5.40285230e-01, 2.17792572e+00, -1.77925722e-02],
    [ 1.83224500e-01, 1.05042958e+01, -2.42957975e-03,
    5.19461244e-01, 2.18322450e+00, -1.83224500e-02]])
    >
    I want to dump it to a plain text file. The problem is, it unravels the
    array. The text file will look like this
    >
    p.xv.tofile('fi le','\n')
    >
    >
    10.3528613872
    -0.0012861387218 8
    0.664009998909
    2.14178590964
    -0.0141785909637
    0.148323738585
    10.3743121062
    -0.0014312106189
    >
    and so on.
    i want it to look like this:
    >
    1 2 3 4 5 6
    7 8 9 10 11 12
    13 14 15 16 17 18
    19 20 21 22 23 24
    >
    >
    any help would be appreciated.
    thanks.
    array is for single dimension arrays.

    You might look at numpy which deals with
    multidimensiona l arrays.

    Colin W.

    Comment

    • gmaximus6@gmail.com

      #3
      Re: Formatting arrays using myarrayy.tolist ()

      sorry, i should've been more specific, this is a numpy array.

      Comment

      • Alan G Isaac

        #4
        Re: Formatting arrays using myarrayy.tolist ()

        <URL:http://www.scipy.org/Cookbook/InputOutput>

        hth,
        Alan Isaac

        Comment

        • Robert Kern

          #5
          Re: Formatting arrays using myarrayy.tolist ()

          gmaximus6@gmail .com wrote:
          sorry, i should've been more specific, this is a numpy array.
          It's usually best to ask numpy questions on the numpy mailing list for this reason.



          --
          Robert Kern

          "I have come to believe that the whole world is an enigma, a harmless enigma
          that is made terrible by our own mad attempt to interpret it as though it had
          an underlying truth."
          -- Umberto Eco

          Comment

          Working...