byteswap() looks like a general endian solution for ndarrays:
https://stackoverflow.com/questions/49578507/fast-way-to-reverse-float32-endianness-in-binary-file
numpy.memmap(infile, dtype=numpy.int32).byteswap().tofile(outfile)
numpy.memmap(infile, dtype=numpy.int32).byteswap(inplace=True).flush()
Bill
On 2023-01-01 08:31, Jerome Kieffer wrote:
On Sun, 01 Jan 2023 05:31:55 -0800
Bill Ross <bross_phobrain@sonic.net> wrote:
Thanks!
Java is known to be big-endian ... your CPU is probably little-endian.
$ lscpu | grep -i endian
Byte Order: Little Endian
Numpy has the tools to represent an array of double BE.
Is there a lower-level ndarray method that writes an array that could be
used this way?
One example:
numpy.array([1,2,3], dtype=">d").tobytes()
b'?\xf0\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00@\x08\x00\x00\x00\x00\x00\x00'
numpy.array([1,2,3], dtype="<d").tobytes()
b'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x08@'
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-leave@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: bross_phobrain@sonic.net