Re: [Numpy-discussion] numpy endian question

2007-04-28 Thread Matthew Brett
On 4/27/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > > Is there really no single method to call on an ndarray that asks: "what > endian are you" > > I know not every two-liner should be made into a convenience method, but > this seems like a good candidate to me. +1 I came across this sour

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Christopher Barker
Is there really no single method to call on an ndarray that asks: "what endian are you" I know not every two-liner should be made into a convenience method, but this seems like a good candidate to me. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, Francesc Altet <[EMAIL PROTECTED]> wrote: > El dj 26 de 04 del 2007 a les 11:38 -0700, en/na Russell E. Owen va > escriure: > > In converting some code from numarray to numpy I had this: > > isBigendian = (arr.isbyteswapped() != numarray.isBigEndian) > > > > The o

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, Christopher Hanley <[EMAIL PROTECTED]> wrote: > Russell, > > This should work as a consistent test for bigendian: > > -> isBigEndian = (obj.dtype.str[0] == '>') > > Also, I have ported numarray's numdisplay to numpy if you would like to > directly display an ar

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Christopher Hanley
Stefan van der Walt wrote: > > Ah, yes, I was confused. What I meant to ask was, couldn't > dtype.str[0] sometimes be '|'? > > That is true. It would happen for an array of strings. >>> a = n.array(['1','2','3','4']) >>> a.dtype.str[0] '|' I haven't needed to worry about that case in te

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Stefan van der Walt
On Fri, Apr 27, 2007 at 08:49:16AM -0400, Christopher Hanley wrote: > >> -> isBigEndian = (obj.dtype.str[0] == '>') > > > > Is this test always safe, even on big endian machines? Couldn't the > > dtype.str[0] sometimes be '='? > > > The test does would on big endian machines. What wouldn't wor

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Christopher Hanley
Stefan van der Walt wrote: > On Thu, Apr 26, 2007 at 05:22:42PM -0400, Christopher Hanley wrote: > >> This should work as a consistent test for bigendian: >> >> -> isBigEndian = (obj.dtype.str[0] == '>') >> > > Is this test always safe, even on big endian machines? Couldn't the > dtype.str

Re: [Numpy-discussion] numpy endian question

2007-04-27 Thread Stefan van der Walt
On Thu, Apr 26, 2007 at 05:22:42PM -0400, Christopher Hanley wrote: > This should work as a consistent test for bigendian: > > -> isBigEndian = (obj.dtype.str[0] == '>') Is this test always safe, even on big endian machines? Couldn't the dtype.str[0] sometimes be '='? Regards Stéfan ___

Re: [Numpy-discussion] numpy endian question

2007-04-26 Thread Travis Oliphant
> I really want to know if the array is in big-endian order (I don't care > whether it's native). This is for sending arrays to the ds9 image viewer > via xpa (and communicating with ds9 is not easy). To do this reliably I > need to indicate the byte order of the data. > Thanks for the clar

Re: [Numpy-discussion] numpy endian question

2007-04-26 Thread Christopher Hanley
Russell, This should work as a consistent test for bigendian: -> isBigEndian = (obj.dtype.str[0] == '>') Also, I have ported numarray's numdisplay to numpy if you would like to directly display an array in DS9. We haven't done an official release yet (sometime soon) but I can forward you a co

Re: [Numpy-discussion] numpy endian question

2007-04-26 Thread Russell E. Owen
In article <[EMAIL PROTECTED]>, Travis Oliphant <[EMAIL PROTECTED]> wrote: > Russell E. Owen asked how best to translate some numarray code that > determines if an array is in big-endian order... > > What are you trying to test for (where a data-type is big-endian or not?). I really want to kno

Re: [Numpy-discussion] numpy endian question

2007-04-26 Thread Travis Oliphant
Russell E. Owen wrote: > In converting some code from numarray to numpy I had this: > isBigendian = (arr.isbyteswapped() != numarray.isBigEndian) > > The only numpy version I've come up with is: > isBigEndian = (arr.dtype.descr[0][1][0] == '>') > > which is short but very obscure. Has anyone got a

Re: [Numpy-discussion] numpy endian question

2007-04-26 Thread Francesc Altet
El dj 26 de 04 del 2007 a les 11:38 -0700, en/na Russell E. Owen va escriure: > In converting some code from numarray to numpy I had this: > isBigendian = (arr.isbyteswapped() != numarray.isBigEndian) > > The only numpy version I've come up with is: > isBigEndian = (arr.dtype.descr[0][1][0] == '>'

[Numpy-discussion] numpy endian question

2007-04-26 Thread Russell E. Owen
In converting some code from numarray to numpy I had this: isBigendian = (arr.isbyteswapped() != numarray.isBigEndian) The only numpy version I've come up with is: isBigEndian = (arr.dtype.descr[0][1][0] == '>') which is short but very obscure. Has anyone got a suggestion for a clearer test? I f