Skip to content

np.sort() - Sort an array #51

@TheWolf313

Description

@TheWolf313

Syntax:
np.sort(a, axis=-1, kind=None, order=None)

a: Input array.

axis: Axis along which to sort. Default is -1 (last axis).

kind: Sorting algorithm: 'quicksort', 'mergesort', 'heapsort', 'stable'. Default is 'quicksort'.

order: When a is a structured array, this specifies which fields to compare first.

Example:
import numpy as np
sorted_arr = np.sort(np.array([3, 1, 2, 5]))
print(sorted_arr)

[1 2 3 5]

import numpy as np
arr = np.array([[3, 1, 2], [9, 5, 7]])
sorted_2d = np.sort(arr, axis=1)
print(sorted_2d)

[[1 2 3]
[5 7 9]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions