Skip to content

np.split() - Split an array into multiple sub-arrays #48

@TheWolf313

Description

@TheWolf313

Syntax:
np.split(ary, indices_or_sections, axis=0)

ary: The array to be split.

indices_or_sections: Number of equal sections or list of indices.

axis: Axis along which to split (default is 0).

import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
split_arr = np.split(arr, 3)
print(split_arr)

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

import numpy as np
matrix = np.array([[1, 2, 3, 4],
[5, 6, 7, 8]])
split_matrix = np.split(matrix, 2, axis=1)
print(split_matrix)

[array([[1, 2],
[5, 6]]),
array([[3, 4],
[7, 8]])]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions