[Numpy-discussion] Arrays as nested dtype

Robert Love rblove_lists at comcast.net
Fri Apr 8 22:23:16 EDT 2011

Using np.loadtxt I can easily read my file that has columns of time, mode, 3 float64 for position and 3 for velocity like this.

dt = dtype([('time', '|S12'), ('mode','|S3'),('rx','f8'),('ry','f8'),('rz','f8'),('vx','f8'),('vy','f8'),('vz','f8')])

data = np.loadtxt('file', dtype=dt)

I can then put the two pairs of 3 components into np.arrays and start performing the vector operations I need.

How can I read them directly into np.arrays?

dt = dtype([('time', '|S12'), ('mode','|S3'),np.array('r'), np.array('v')])

I've seen examples for nested data that create a tuple but not an array.  Any tips  appreciated.

More information about the NumPy-Discussion mailing list