Friday, 23 August 2013

How do I add a column to a 2d array with specific dtype?

How do I add a column to a 2d array with specific dtype?

Here is the code I wrote. The 'guteliste25.txt' contains a data table with
a header where the names of the colums are specified.
import numpy as np
d = 'guteliste25.txt'
CNS = np.genfromtxt(d, dtype = None, names = True)
dt = np.dtype([('R','<f8')])
test = np.ones(len(CNS),dtype=dt)
klaus = np.concatenate((CNS,test), axis=1)
The error it spits out in the last line is: TypeError: expected a readable
buffer object
I think it must be some problem with np.genfromtxt and its formatting of
the different rows.
I just want to add one value to each row, i.e. in total one column and
have a name for it to so that I can access it easily via: CNS['R']

No comments:

Post a Comment