Skip to content

Commit 7e154b1

Browse files
authored
Update byteswap.md
1 parent f1b7777 commit 7e154b1

File tree

1 file changed

+7
-7
lines changed
  • content/numpy/concepts/ndarray/terms/byteswap

1 file changed

+7
-7
lines changed

content/numpy/concepts/ndarray/terms/byteswap/byteswap.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ndarray.byteswap(inplace=False)
2323

2424
**Parameters:**
2525

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.
2727

2828
**Return value:**
2929

@@ -57,7 +57,7 @@ Original array:
5757
Original dtype: int32
5858

5959
After byteswap():
60-
[16777216 1 4]
60+
[16777216 65536 262144]
6161
Swapped dtype: int32
6262
```
6363

@@ -81,12 +81,12 @@ The output of this code is:
8181

8282
```shell
8383
Before inplace byteswap: [100 200 300]
84-
After inplace byteswap: [1677721600 335544320 503316480]
84+
After inplace byteswap: [1677721600 -939524096 738263040]
8585
```
8686

8787
## Codebyte Example
8888

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:
9090

9191
```codebyte/python
9292
import numpy as np
@@ -102,15 +102,15 @@ print("\nByteswapped:")
102102
print(swapped)
103103
```
104104

105-
## Frequently Asked Question
105+
## Frequently Asked Questions
106106

107-
### 1. What is the function of byteswap in Python?
107+
### 1. What is the function of byteswap() in Python?
108108

109109
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.
110110

111111
### 2. What are bytes and bytearrays in Python?
112112

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.
114114

115115
### 3. How to shuffle a NumPy ndarray?
116116

0 commit comments

Comments
 (0)