You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ``ndarray`` is an object that provide a python array interface to data in memory.
5
+
``ndarray``是一个为内存中的数据提供python数组接口的对象。
6
6
7
-
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.
7
+
经常发生的情况是,要用数组查看的内存与运行Python的计算机的字节顺序不同。
8
8
9
-
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:
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:
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:
@@ -32,21 +32,21 @@ We might want to use an ``ndarray`` to access these integers. In that case, we c
32
32
770
33
33
```
34
34
35
-
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``.
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.
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:
60
+
从介绍中可以想象,有两种方法可以影响数组的字节顺序与它所查看的底层内存之间的关系:
61
61
62
-
-Change the byte-ordering information in the array dtype so that it interprets the underlying data as being in a different byte order. This is the role of``arr.newbyteorder()``
63
-
-Change the byte-ordering of the underlying data, leaving the dtype interpretation as it was. This is what ``arr.byteswap()`` does.
### Data and type endianness don’t match, change data to match dtype
96
+
### 数据和类型字节顺序不匹配,更改数据以匹配dtype
97
97
98
-
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.
### Data and dtype endianness match, swap data and dtype
113
+
### 数据和dtype字节序匹配,交换数据和dtype
114
114
115
-
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:
0 commit comments