Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-18 Thread Robert Kern
On Fri, Jun 18, 2010 at 09:39, Benjamin Root wrote: > Just for my own knowledge, would Robert's suggestion of using '>i2' as the > dtype be considered the "best" solution, mostly because of its simplicity, > but also because it does not assume the endian-ness of the host computer? It does come w

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-18 Thread Benjamin Root
On Fri, Jun 18, 2010 at 6:15 AM, Sturla Molden wrote: > Den 17.06.2010 16:29, skrev greg whittier: > > I have files (from an external source) that contain ~10 GB of > > big-endian uint16's that I need to read into a series of arrays. What > > I'm doing now is > > > > import numpy as np > > impor

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-18 Thread Sturla Molden
Den 17.06.2010 16:29, skrev greg whittier: > I have files (from an external source) that contain ~10 GB of > big-endian uint16's that I need to read into a series of arrays. What > I'm doing now is > > import numpy as np > import struct > > fd = open('file.raw', 'rb') > > for n in range(1) >

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread greg whittier
On Thu, Jun 17, 2010 at 12:11 PM, Peter wrote: > On Thu, Jun 17, 2010 at 3:29 PM, greg whittier wrote: > I'm unclear if you want a numpy array or a standard library array, > but can you exploit the fact that struct.unpack returns a tuple? e.g. > > struct.unpack(">%iH" % count, fd.read(2*count)) >

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread Peter
On Thu, Jun 17, 2010 at 3:29 PM, greg whittier wrote: > > I have files (from an external source) that contain ~10 GB of > big-endian uint16's that I need to read into a series of arrays.  What > I'm doing now is > > import numpy as np > import struct > > fd = open('file.raw', 'rb') > > for n in ra

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread greg whittier
On Thu, Jun 17, 2010 at 10:41 AM, Robert Kern wrote: > On Thu, Jun 17, 2010 at 09:29, greg whittier wrote: >> I have files (from an external source) that contain ~10 GB of >> big-endian uint16's that I need to read into a series of arrays. > > np.fromfile(filename, dtype='>i2') > > -- > Robert Ke

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread Robert Kern
On Thu, Jun 17, 2010 at 09:46, Francesc Alted wrote: > A Thursday 17 June 2010 16:29:54 greg whittier escrigué: >> I have files (from an external source) that contain ~10 GB of >> big-endian uint16's that I need to read into a series of arrays.  What >> I'm doing now is >> >> import numpy as np >>

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread Francesc Alted
A Thursday 17 June 2010 16:29:54 greg whittier escrigué: > I have files (from an external source) that contain ~10 GB of > big-endian uint16's that I need to read into a series of arrays. What > I'm doing now is > > import numpy as np > import struct > > fd = open('file.raw', 'rb') > > for n in

Re: [Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread Robert Kern
On Thu, Jun 17, 2010 at 09:29, greg whittier wrote: > I have files (from an external source) that contain ~10 GB of > big-endian uint16's that I need to read into a series of arrays. np.fromfile(filename, dtype='>i2') -- Robert Kern "I have come to believe that the whole world is an enigma, a

[Numpy-discussion] reading big-endian uint16 into array on little-endian machine

2010-06-17 Thread greg whittier
I have files (from an external source) that contain ~10 GB of big-endian uint16's that I need to read into a series of arrays. What I'm doing now is import numpy as np import struct fd = open('file.raw', 'rb') for n in range(1) count = 1024*1024 a = np.array([struct.unpack('>H', fd.