[Tutor] Appending an extra column in a data file

Andre' Walker-Loud walksloud at gmail.com
Wed Apr 10 19:08:51 CEST 2013


Hi Sayan,

> Thank Andre for your prompt answer. 

No problem.

> I'll figure out the plotting issue once the dat files are made. So it's the primary concern.
> For an example I am attaching a dat file herewith. The two columns here are 2 numpy arrays.I want to add a third column, to be precise, I want to print a parameter value on the third column of the file.

Let me try again.
The reason the matplotlib list would be a better place is this is a general python list, and most people are not familiar with numpy.  However, most people who use matplotlib are familiar with numpy.

I am hoping you can describe precisely the structure of the data.  Maybe show a little code on how it is created, or how you access it.  I am not keen to open "random" files from the internet.  As two examples of how I think your code might be packed

1/
'''
x = numpy.zeros([10]) # 1D numpy array of dimension 10
y = numpy.zeros([10]) # 1D numpy array of dimension 10
your_data = []
your_data.append(x)
your_data.append(y)
'''

so now your data is a table with two entries, and each entry is a numpy array.
You have in mind adding a third entry to the table with just floats.

2/
'''
your_data = numpy.zeros([10,10]) # initialize a 2D numpy array with all zeros
for i in range(your_data.shape[0]):
    for j in range(your_data.shape[1]):
        your_data[i,j] = data[i][j] # I am assuming the data is imported already and called data and is in a python list/table format
'''

Now you want to make a new column or row for your data file, which contains floats.  Well, all the entries inside the numpy array are already floats, so it is not clear to me why you want a new column that is not a numpy array. So it would be nice if you could precisely describe what you currently have and what you want.


Hope this helps,

Andre




More information about the Tutor mailing list