arr.dtype.byteorder == '=' --- is this "good code"
Hi, Suppose I'm on a little-edian system. Could I have a little-endian numpy array arr, where arr.dtype.byteorder would actually be "<" instead of "=" !? There are two kinds of systems: little edian and big endian. But there are three possible byteorder values: "<", ">" and "=" I assume that if arr.dtype.byteorder is "=" then, even on a little endian system the comparison arr.dtype.byteorder == "<" still fails !? Or are the == and != operators overloaded !? Thanks, Sebastian Haase
any comments !? On 6/25/07, Sebastian Haase <haase@msg.ucsf.edu> wrote:
Hi, Suppose I'm on a little-edian system. Could I have a little-endian numpy array arr, where arr.dtype.byteorder would actually be "<" instead of "=" !?
There are two kinds of systems: little edian and big endian. But there are three possible byteorder values: "<", ">" and "="
I assume that if arr.dtype.byteorder is "=" then, even on a little endian system the comparison arr.dtype.byteorder == "<" still fails !? Or are the == and != operators overloaded !?
Thanks, Sebastian Haase
El dt 03 de 07 del 2007 a les 08:35 +0200, en/na Sebastian Haase va escriure:
any comments !?
On 6/25/07, Sebastian Haase <haase@msg.ucsf.edu> wrote:
Hi, Suppose I'm on a little-edian system. Could I have a little-endian numpy array arr, where arr.dtype.byteorder would actually be "<" instead of "=" !?
You can always use arr.dtype.str[0], which I think it always returns a '<', '>' or '|': In [2]:a=numpy.array([1]) In [3]:a.dtype.byteorder Out[3]:'=' In [4]:a.dtype.str Out[4]:'<i4' In [5]:a.dtype.str[0] Out[5]:'<'
There are two kinds of systems: little edian and big endian. But there are three possible byteorder values: "<", ">" and "="
I assume that if arr.dtype.byteorder is "=" then, even on a little endian system the comparison arr.dtype.byteorder == "<" still fails !? Or are the == and != operators overloaded !?
No, this will fail. The == and != are not overloaded because dtype.byteorder is a pure python string: In [11]:type(a.dtype.byteorder) Out[11]:<type 'str'> Cheers, -- Francesc Altet | Be careful about using the following code -- Carabos Coop. V. | I've only proven that it works, www.carabos.com | I haven't tested it. -- Donald Knuth
Thanks for the reply. Rethinking the question ... wasn't there an attribute named something like: is_native() ?? The a.dtype.str[0] is certainly better than nothing ... just doesn't look very good ;-) -Sebastian On 7/3/07, Francesc Altet <faltet@carabos.com> wrote:
El dt 03 de 07 del 2007 a les 08:35 +0200, en/na Sebastian Haase va escriure:
any comments !?
On 6/25/07, Sebastian Haase <haase@msg.ucsf.edu> wrote:
Hi, Suppose I'm on a little-edian system. Could I have a little-endian numpy array arr, where arr.dtype.byteorder would actually be "<" instead of "=" !?
You can always use arr.dtype.str[0], which I think it always returns a '<', '>' or '|':
In [2]:a=numpy.array([1]) In [3]:a.dtype.byteorder Out[3]:'=' In [4]:a.dtype.str Out[4]:'<i4' In [5]:a.dtype.str[0] Out[5]:'<'
There are two kinds of systems: little edian and big endian. But there are three possible byteorder values: "<", ">" and "="
I assume that if arr.dtype.byteorder is "=" then, even on a little endian system the comparison arr.dtype.byteorder == "<" still fails !? Or are the == and != operators overloaded !?
No, this will fail. The == and != are not overloaded because dtype.byteorder is a pure python string:
In [11]:type(a.dtype.byteorder) Out[11]:<type 'str'>
El dt 03 de 07 del 2007 a les 10:34 +0200, en/na Sebastian Haase va escriure:
Thanks for the reply. Rethinking the question ... wasn't there an attribute named something like: is_native() ??
In [3]:a.dtype.isnative Out[3]:True :) -- Francesc Altet | Be careful about using the following code -- Carabos Coop. V. | I've only proven that it works, www.carabos.com | I haven't tested it. -- Donald Knuth
participants (2)
-
Francesc Altet -
Sebastian Haase