Linux server.edchosting.com 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
LiteSpeed
Server IP : 75.98.162.185 & Your IP : 216.73.216.163
Domains :
Cant Read [ /etc/named.conf ]
User : goons4good
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
lib64 /
python2.7 /
site-packages /
numpy /
doc /
Delete
Unzip
Name
Size
Permission
Date
Action
__init__.py
517
B
-rw-r--r--
2013-04-07 01:04
__init__.pyc
783
B
-rw-r--r--
2018-04-10 19:40
__init__.pyo
783
B
-rw-r--r--
2018-04-10 19:40
basics.py
5.2
KB
-rw-r--r--
2013-04-07 01:04
basics.pyc
5.35
KB
-rw-r--r--
2018-04-10 19:40
basics.pyo
5.35
KB
-rw-r--r--
2018-04-10 19:40
broadcasting.py
5.38
KB
-rw-r--r--
2013-04-07 01:04
broadcasting.pyc
5.54
KB
-rw-r--r--
2018-04-10 19:40
broadcasting.pyo
5.54
KB
-rw-r--r--
2018-04-10 19:40
byteswapping.py
4.67
KB
-rw-r--r--
2013-04-07 01:04
byteswapping.pyc
4.83
KB
-rw-r--r--
2018-04-10 19:40
byteswapping.pyo
4.83
KB
-rw-r--r--
2018-04-10 19:40
constants.py
8.68
KB
-rw-r--r--
2013-04-07 01:04
constants.pyc
7.94
KB
-rw-r--r--
2018-04-10 19:40
constants.pyo
7.94
KB
-rw-r--r--
2018-04-10 19:40
creation.py
5.28
KB
-rw-r--r--
2013-04-07 01:04
creation.pyc
5.44
KB
-rw-r--r--
2018-04-10 19:40
creation.pyo
5.44
KB
-rw-r--r--
2018-04-10 19:40
glossary.py
11.7
KB
-rw-r--r--
2013-04-07 01:04
glossary.pyc
11.85
KB
-rw-r--r--
2018-04-10 19:40
glossary.pyo
11.85
KB
-rw-r--r--
2018-04-10 19:40
howtofind.py
94
B
-rw-r--r--
2013-04-07 01:04
howtofind.pyc
254
B
-rw-r--r--
2018-04-10 19:40
howtofind.pyo
254
B
-rw-r--r--
2018-04-10 19:40
indexing.py
13.95
KB
-rw-r--r--
2013-04-07 01:04
indexing.pyc
14.11
KB
-rw-r--r--
2018-04-10 19:40
indexing.pyo
14.11
KB
-rw-r--r--
2018-04-10 19:40
internals.py
9.38
KB
-rw-r--r--
2013-04-07 01:04
internals.pyc
9.54
KB
-rw-r--r--
2018-04-10 19:40
internals.pyo
9.54
KB
-rw-r--r--
2018-04-10 19:40
io.py
82
B
-rw-r--r--
2013-04-07 01:04
io.pyc
235
B
-rw-r--r--
2018-04-10 19:40
io.pyo
235
B
-rw-r--r--
2018-04-10 19:40
jargon.py
96
B
-rw-r--r--
2013-04-07 01:04
jargon.pyc
253
B
-rw-r--r--
2018-04-10 19:40
jargon.pyo
253
B
-rw-r--r--
2018-04-10 19:40
methods_vs_functions.py
130
B
-rw-r--r--
2013-04-07 01:04
methods_vs_functions.pyc
301
B
-rw-r--r--
2018-04-10 19:40
methods_vs_functions.pyo
301
B
-rw-r--r--
2018-04-10 19:40
misc.py
5.97
KB
-rw-r--r--
2013-04-07 01:04
misc.pyc
6.12
KB
-rw-r--r--
2018-04-10 19:40
misc.pyo
6.12
KB
-rw-r--r--
2018-04-10 19:40
performance.py
100
B
-rw-r--r--
2013-04-07 01:04
performance.pyc
262
B
-rw-r--r--
2018-04-10 19:40
performance.pyo
262
B
-rw-r--r--
2018-04-10 19:40
structured_arrays.py
8.56
KB
-rw-r--r--
2013-04-07 01:04
structured_arrays.pyc
8.72
KB
-rw-r--r--
2018-04-10 19:40
structured_arrays.pyo
8.72
KB
-rw-r--r--
2018-04-10 19:40
subclassing.py
19.69
KB
-rw-r--r--
2013-04-07 01:04
subclassing.pyc
19.85
KB
-rw-r--r--
2018-04-10 19:40
subclassing.pyo
19.85
KB
-rw-r--r--
2018-04-10 19:40
ufuncs.py
5.24
KB
-rw-r--r--
2013-04-07 01:04
ufuncs.pyc
5.39
KB
-rw-r--r--
2018-04-10 19:40
ufuncs.pyo
5.39
KB
-rw-r--r--
2018-04-10 19:40
Save
Rename
''' ============================= Byteswapping and byte order ============================= Introduction to byte ordering and ndarrays ========================================== The ``ndarray`` is an object that provide a python array interface to data in memory. It often happens that the memory that you want to view with an array is not of the same byte ordering as the computer on which you are running Python. For example, I might be working on a computer with a little-endian CPU - such as an Intel Pentium, but I have loaded some data from a file written by a computer that is big-endian. Let's say I have loaded 4 bytes from a file written by a Sun (big-endian) computer. I know that these 4 bytes represent two 16-bit integers. On a big-endian machine, a two-byte integer is stored with the Most Significant Byte (MSB) first, and then the Least Significant Byte (LSB). Thus the bytes are, in memory order: #. MSB integer 1 #. LSB integer 1 #. MSB integer 2 #. LSB integer 2 Let's say the two integers were in fact 1 and 770. Because 770 = 256 * 3 + 2, the 4 bytes in memory would contain respectively: 0, 1, 3, 2. The bytes I have loaded from the file would have these contents: >>> big_end_str = chr(0) + chr(1) + chr(3) + chr(2) >>> big_end_str '\\x00\\x01\\x03\\x02' We might want to use an ``ndarray`` to access these integers. In that case, we can create an array around this memory, and tell numpy that there are two integers, and that they are 16 bit and big-endian: >>> import numpy as np >>> big_end_arr = np.ndarray(shape=(2,),dtype='>i2', buffer=big_end_str) >>> big_end_arr[0] 1 >>> big_end_arr[1] 770 Note the array ``dtype`` above of ``>i2``. The ``>`` means 'big-endian' (``<`` is little-endian) and ``i2`` means 'signed 2-byte integer'. For example, if our data represented a single unsigned 4-byte little-endian integer, the dtype string would be ``<u4``. In fact, why don't we try that? >>> little_end_u4 = np.ndarray(shape=(1,),dtype='<u4', buffer=big_end_str) >>> little_end_u4[0] == 1 * 256**1 + 3 * 256**2 + 2 * 256**3 True Returning to our ``big_end_arr`` - in this case our underlying data is big-endian (data endianness) and we've set the dtype to match (the dtype is also big-endian). However, sometimes you need to flip these around. Changing byte ordering ====================== As you can imagine from the introduction, there are two ways you can affect the relationship between the byte ordering of the array and the underlying memory it is looking at: * Change the byte-ordering information in the array dtype so that it interprets the undelying data as being in a different byte order. This is the role of ``arr.newbyteorder()`` * Change the byte-ordering of the underlying data, leaving the dtype interpretation as it was. This is what ``arr.byteswap()`` does. The common situations in which you need to change byte ordering are: #. Your data and dtype endianess don't match, and you want to change the dtype so that it matches the data. #. Your data and dtype endianess don't match, and you want to swap the data so that they match the dtype #. Your data and dtype endianess match, but you want the data swapped and the dtype to reflect this Data and dtype endianness don't match, change dtype to match data ----------------------------------------------------------------- We make something where they don't match: >>> wrong_end_dtype_arr = np.ndarray(shape=(2,),dtype='<i2', buffer=big_end_str) >>> wrong_end_dtype_arr[0] 256 The obvious fix for this situation is to change the dtype so it gives the correct endianness: >>> fixed_end_dtype_arr = wrong_end_dtype_arr.newbyteorder() >>> fixed_end_dtype_arr[0] 1 Note the the array has not changed in memory: >>> fixed_end_dtype_arr.tostring() == big_end_str True Data and type endianness don't match, change data to match dtype ---------------------------------------------------------------- You might want to do this if you need the data in memory to be a certain ordering. For example you might be writing the memory out to a file that needs a certain byte ordering. >>> fixed_end_mem_arr = wrong_end_dtype_arr.byteswap() >>> fixed_end_mem_arr[0] 1 Now the array *has* changed in memory: >>> fixed_end_mem_arr.tostring() == big_end_str False Data and dtype endianness match, swap data and dtype ---------------------------------------------------- You may have a correctly specified array dtype, but you need the array to have the opposite byte order in memory, and you want the dtype to match so the array values make sense. In this case you just do both of the previous operations: >>> swapped_end_arr = big_end_arr.byteswap().newbyteorder() >>> swapped_end_arr[0] 1 >>> swapped_end_arr.tostring() == big_end_str False '''