473,224 Members | 1,345 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,224 software developers and data experts.

Array into a TXT file without [[ ]]

Good morning, I am new to python, but I need it for my research in computational climate simulations for its power.

I need to write a 2D array into a text file, but what I obtain is the correct array, although each value appears within [[ ]];
I use the scripting written below, how should I modify it in order to avoid it to write the parenthesis?

for time in range(data_var_model.shape[0]):
outfile_model=open('msl_data_model.txt','a')
outfile_model.write(str(data_var_model[time,:,:])+' ')
outfile_model.write('\n')

With this routine the output looks this way:

[[ [ 101135.46875 ]]
[ [ 101137.046875 ]]
[ [ 101132.5546875]]
[ [ 101133.2109375]]
[ [ 101131.5703125]]
[ [ 101131.65625 ]]
[ [ 101135.890625 ]]
[ [ 101133.203125 ]]
[ [ 101130.5234375]]
[ [ 101134.0390625]]]


Thanks a lot,
simone
Jul 20 '07 #1
1 7262
bvdet
2,851 Expert Mod 2GB
Good morning, I am new to python, but I need it for my research in computational climate simulations for its power.

I need to write a 2D array into a text file, but what I obtain is the correct array, although each value appears within [[ ]];
I use the scripting written below, how should I modify it in order to avoid it to write the parenthesis?

for time in range(data_var_model.shape[0]):
outfile_model=open('msl_data_model.txt','a')
outfile_model.write(str(data_var_model[time,:,:])+' ')
outfile_model.write('\n')

With this routine the output looks this way:

[[ [ 101135.46875 ]]
[ [ 101137.046875 ]]
[ [ 101132.5546875]]
[ [ 101133.2109375]]
[ [ 101131.5703125]]
[ [ 101131.65625 ]]
[ [ 101135.890625 ]]
[ [ 101133.203125 ]]
[ [ 101130.5234375]]
[ [ 101134.0390625]]]


Thanks a lot,
simone
It may help if you could show us what this object is: data_var_model
I'll take a shot anyway:
Expand|Select|Wrap|Line Numbers
  1. dataList = []
  2. for time in range(data_var_model.shape[0]):
  3.     dataList.append(data_var_model[time,:,:]) # this line contains an invalid slice
  4. outfile_model=open('msl_data_model.txt','a')
  5. outfile_model.write('\n'.join([str(d[0][0]) for d in dataList]))
  6. outfile_model.close()
Jul 20 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Randell D. | last post by:
Folks, Here's my problem: I am createing an array in a file using the reslut of some PHP and MySQL processing. An example of my array would be examlpe="example one"; examlpe="example...
11
by: Jeevan | last post by:
Hi, I have some data which I am getting from a socket. I am currently storing the data in an array (so that future reading of the data will be fast as it will be in RAM instead of hard disk)....
8
by: Michel Rouzic | last post by:
I had a program that worked perfectly, and that read .wav files. I changed something so the tags of the wave file, instead of being each in a different variable, are all in an array, called tag. i...
2
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
4
by: Haydnw | last post by:
Hi, I'd like to put a load of database results (several rows for 5 fields) into a two-dimensional array. Now, this may be a really stupid question, but can someone give me a pointer for how to...
6
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as...
1
by: jef.d | last post by:
I am attempting to read through a text file & then update an HTML page table w/ the output from the text file (ie; statusing by table). What I want the code to do is read through the file, look...
2
by: Kelly | last post by:
Hi all, I am trying without much success to understand someone else's VB program. To make things a little easier to compare side by side, I wanted to print some of the variables being used...
9
by: herobeat | last post by:
Hi all, I'm having a hell of a time with declaring a struct to hold some binary data I'm trying to read from some files on disk. What I would like to do is something like this: public struct...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.