NumPy Splitting Array | How to Split NumPy Arrays@arvindprogramming

preview_player
Показать описание
NumPy Splitting Array | How to Split NumPy Arrays @arvindprogramming

```python
```

- `array`: The input array that you want to split.
- `indices_or_sections`: This parameter specifies the indices or sections where the array is to be split. It can have the following forms:
- An integer, `n`, indicating how many equally-sized pieces to split the array into.
- A 1-D array of sorted integers, indicating the indices where the array is to be split.
- `axis` (optional): It represents the axis along which the array is split. The default value is 0.

Here is an example of splitting a NumPy array into two sub-arrays:

```python
import numpy as np

# Create an array

# Split the array into two sub-arrays

print(sub_arrays)
```

Output:
```
[array([1, 2, 3]), array([4, 5, 6])]
```

In this example, the array `[1, 2, 3, 4, 5, 6]` is split into two sub-arrays of equal size along the default axis (`axis=0`). The resulting sub-arrays are `[array([1, 2, 3]), array([4, 5, 6])]`.

You can also split arrays along different axes or specify different indices or sections based on your requirements.
Social Media Links-
Рекомендации по теме