Formatting arrays using myarrayy.tolist()

M

Max Abrahams

I've got an array that looks like this:


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('file','\n')


10.3528613872
-0.00128613872188
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.
 
C

Colin J. Williams

Max said:
I've got an array that looks like this:


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('file','\n')


10.3528613872
-0.00128613872188
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
multidimensional arrays.

Colin W.
 
R

Robert Kern

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.

http://www.scipy.org/Mailing_Lists

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top