[Tutor] Appending an extra column in a data file

Sayan Chatterjee sayanchatterjee at gmail.com
Wed Apr 10 19:46:46 CEST 2013


Hi Alan,

Sorry for the ambiguity I have created.

 I have added the snippet of code just in the previous mail and also the
sample data in the text file. Have you had a look on them?

I am copy pasting it in this email:

Hi Andre,

Well,this is the concerned snippet of the code:


while *t < 1*:


  pp_za = pp_init + t*K*np.sin(K*pp_init)

# Periodic Boundary Condition

  for i in range(0,999):

    if pp_za[i] < 0:
      pp_za[i] = 2 - abs(pp_za[i])
    if pp_za[i] > 2:
      pp_za[i] = pp_za[i] % 2

  pv_za = +K*np.sin(K*pp_init)

  fname = 'file_' + str(t) + '.dat'

# Generating dataset for Phase Space diagram

  *np.savetxt(fname, np.array([pp_za,pv_za]).T, '%f')*

  t = t + 0.01

And the sample data generated is :

0.105728 0.098678
0.126865 0.118406
0.147998 0.138128
0.169126 0.157845
0.190247 0.177556
0.211362 0.197259
0.232469 0.216955
0.253567 0.236643
0.274657 0.256321
0.295737 0.275989
0.316806 0.295646

Precisely what I want is, I want to add the 't' (over which the while loop
is run) in the 3 rd column. 't' is float and constant for each looping. If
you know what a phase plot is(doesn't matter if you don't), I want to see
the phase plot evolving with time. Thus the need of a time axis and hence
plot with V(velocity-Yaxis), X ( Position -X axis) and t (Time-Z axis).


Regards,
Sayan




On 10 April 2013 23:07, Alan Gauld <alan.gauld at btinternet.com> wrote:

> On 10/04/13 16:44, Sayan Chatterjee wrote:
>
>  I have some data files with numpy arrays stored in it in 2 columns. I
>>
>
> Can you define what that means?
> All files on a computer are data files in some sense.
> They exist as text files or binary files. If they are text files then the
> content of your arrays must be encoded somehow as strings. If they are
> binary files you must have dumped them to file somehow and adding floats is
> something you probably need to figure out yourself!
>
> How did you create these files? (Or how were they created buy somebody
> else?)
>
>
>  want to add a third column with just floating point numbers(not numpy
>> array) and plot them later with Matplotlib in 3d. How is it done? Could
>> you please illuminate me?
>>
>
> The fact you use the term column suggests that maybe they are text files
> of some kind in which case you likely have the content of the numpy arrays
> but not their structure, in which case adding an extra column should be
> easy by following the pattern of how you created the files. Don't forget to
> modify the functions that read the data back to match.
>
> But with no idea of the exact nature of your "data files" we can't give
> very specific help.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ______________________________**_________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 


--------------------------------------------------------------------------
*Sayan  Chatterjee*
Dept. of Physics and Meteorology
IIT Kharagpur
Lal Bahadur Shastry Hall of Residence
Room AB 205
Mob: +91 9874513565
blog: www.blissprofound.blogspot.com

Volunteer , Padakshep
www.padakshep.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130410/6befa229/attachment.html>


More information about the Tutor mailing list