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
Copy file name to clipboardExpand all lines: content/numpy/concepts/ndarray/terms/byteswap/byteswap.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ ndarray.byteswap(inplace=False)
23
23
24
24
**Parameters:**
25
25
26
-
-`inplace` (optional): When set to `True`, the byte order of the existing array is swapped in place. When False, a new array with swapped bytes is returned.
26
+
-`inplace` (optional): When set to `True`, the byte order of the existing array is swapped in place. When `False`, a new array with swapped bytes is returned.
27
27
28
28
**Return value:**
29
29
@@ -57,7 +57,7 @@ Original array:
57
57
Original dtype: int32
58
58
59
59
After byteswap():
60
-
[16777216 1 4]
60
+
[16777216 65536262144]
61
61
Swapped dtype: int32
62
62
```
63
63
@@ -81,12 +81,12 @@ The output of this code is:
81
81
82
82
```shell
83
83
Before inplace byteswap: [100 200 300]
84
-
After inplace byteswap: [1677721600 335544320 503316480]
84
+
After inplace byteswap: [1677721600 -939524096 738263040]
85
85
```
86
86
87
87
## Codebyte Example
88
88
89
-
Use the Codebyte below to inspect how byteswap affects a 2-D array and observe the internal memory representation change:
89
+
Use the codebyte below to inspect how `byteswap()` affects a 2-D array and observe the internal memory representation change:
90
90
91
91
```codebyte/python
92
92
import numpy as np
@@ -102,15 +102,15 @@ print("\nByteswapped:")
102
102
print(swapped)
103
103
```
104
104
105
-
## Frequently Asked Question
105
+
## Frequently Asked Questions
106
106
107
-
### 1. What is the function of byteswap in Python?
107
+
### 1. What is the function of byteswap() in Python?
108
108
109
109
The `byteswap()` method reverses the byte order of every element in a NumPy array. It is commonly used when preparing data for systems with different endianness or when interpreting binary data from external sources.
110
110
111
111
### 2. What are bytes and bytearrays in Python?
112
112
113
-
A `bytes` object is an immutable sequence of byte values, while a bytearray is a mutable version of the same concept. Both store raw binary data and are often used for file handling, networking, and low-level memory operations.
113
+
A `bytes` object in Python is an immutable sequence of byte values, while a bytearray is a mutable version of the same concept. Both store raw binary data and are often used for file handling, networking, and low-level memory operations.
0 commit comments