[Numpy-discussion] numpy.ascontiguousarray on byteswapped data !?
haase at msg.ucsf.edu
Fri Aug 11 14:22:01 CDT 2006
On Thursday 10 August 2006 21:32, Sebastian Haase wrote:
> Travis Oliphant wrote:
> > Sebastian Haase wrote:
> >> Hi,
> >> Does numpy.ascontiguousarray(arr) "fix" the byteorder when arr is
> >> non-native byteorder ?
> >> If not, what functions does ?
> > It can if you pass in a data-type with the right byteorder (or use a
> > native built-in data-type).
> > In NumPy, it's the data-type that carries the "byte-order"
> > information. So, there are lot's of ways to "fix" the byte-order.
> So then the question is: what is the easiest way to say:
> give me the equivalent type of dtype, but with byteorder '<' (or '=') !?
> I would be cumbersome (and ugly ;-) ) if one would have to "manually
> assemble" such a construct every time ...
I just found this in myCVS/numpy/numpy/core/tests/test_numerictypes.py
"Normalize a description adding the platform byteorder."
out = 
for item in descr:
dtype = item
if isinstance(dtype, str):
if dtype not in ['|','<','>']:
onebyte = dtype[1:] == "1"
if onebyte or dtype in ['S', 'V', 'b']:
dtype = "|" + dtype
dtype = byteorder + dtype
if len(item) > 2 and item > 1:
nitem = (item, dtype, item)
nitem = (item, dtype)
elif isinstance(item, list):
l = 
for j in normalize_descr(item):
raise ValueError("Expected a str or list and got %s" % \
Is that what I was talking about !? It's quite a big animal.
Would this be needed "everytime" I want to get a "systembyte-ordered version"
of a given type !?
> > Of course there is still the difference between "fixing" the byte-order
> > and simply "viewing" the memory in the correct byte-order. The former
> > physically flips bytes around, the latter just flips them on calculation
> > and presentation.
> I understand. I need something that I can feed into my C routines that
> are to dumb to handle non-contiguous or byte-swapped data .
> - Sebastian
More information about the Numpy-discussion