473,396 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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('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.
Feb 6 '08 #1
4 2439
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('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.
Feb 6 '08 #2
sorry, i should've been more specific, this is a numpy array.
Feb 6 '08 #3
<URL:http://www.scipy.org/Cookbook/InputOutput>

hth,
Alan Isaac
Feb 6 '08 #4
gm*******@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.

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

Feb 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
3
by: Kermit Rose | last post by:
From: Kermit Rose Date: 02/10/06 17:36:34 To: python-help@python.org Subject: Arrays Hello. I want to write a program in python using integer arrays.
9
by: David Jackson | last post by:
Hello, Is there anything in the framework which will format a date to show the ordinal representation of the day value e.g. 28th June 2007 1st August 2007 instead of
0
by: macbasic | last post by:
Hi, I am a learner who is automating some data from reports to ease my month end pressures. The code below is used to open a text file (a report from our ERP) and seperate the text into columns. Two...
11
by: pompair | last post by:
Hi, Does anyone know how to use anonymous types in a list? I mean, if you define in your code three anonymous types: new {FirstName = "Donald", LastName = "Duck"}; new {FirstName =...
3
by: Marc S | last post by:
var qry = from s in dbCxt.Services from j in s.Jobs where s.ID == 200 select new { s, j }; I want to call qry.ToList() but with the list containing anonomyous types I don't know how to...
6
by: tshad | last post by:
I am looking for a way to combine 2 string arrays. I am trying to get a list of files from 2 directories and combine them: string strFiles; string strFiles2; strFiles =...
30
by: Ivan Reborin | last post by:
Hello everyone, I was wondering if anyone here has a moment of time to help me with 2 things that have been bugging me. 1. Multi dimensional arrays - how do you load them in python For...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.