From: Christopher B. <Chr...@no...> - 2006-11-08 00:54:02
|
Hi all, I'm using a recarray to read a bunch of binary data out of a file. It's working great, but it seems there should be a more efficient way to "slice" the data. Here's what I've got: The binary data is essentially a dump of a 2-d array of structs. So I read it like this: DataType = N.dtype([("long","i4"), ("lat", "i4"), ("flag","b1")]) data = N.fromfile(file, DataType) data.shape = (M, N) So I now have a MxN array of the structs. What I would like to do is extract a MxNx2 array of just the two 4-byte integers. It seems that I should be able to do that without copying -- by using a view into the original data. I can't figure out how, however. What I am doing is: LEs = N.empty((M, N, 2), dtype=N.int32) LEs[:,:,0] = data['long'] LEs[:,:,1] = data['lat'] This works, but these are BIG files, so it would be nice not to be doing that extra copying. Is that possible? Thanks, -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |