numpy.sort() in Python (original) (raw)
Last Updated : 29 Nov, 2018
numpy.sort() : This function returns a sorted copy of an array.
Parameters :
arr : Array to be sorted.
axis : Axis along which we need array to be started.
order : This argument specifies which fields to compare first.
kind : [‘quicksort’{default}, ‘mergesort’, ‘heapsort’]Sorting algorithm.
Return :
Sorted Array
import
numpy as np
a
=
np.array([[
12
,
15
], [
10
,
1
]])
arr1
=
np.sort(a, axis
=
0
)
print
(
"Along first axis : \n"
, arr1)
a
=
np.array([[
10
,
15
], [
12
,
1
]])
arr2
=
np.sort(a, axis
=
-
1
)
print
(
"\nAlong first axis : \n"
, arr2)
a
=
np.array([[
12
,
15
], [
10
,
1
]])
arr1
=
np.sort(a, axis
=
None
)
print
(
"\nAlong none axis : \n"
, arr1)
Output :
Along first axis : [[10 1] [12 15]]
Along first axis : [[10 15] [ 1 12]]
Along none axis : [ 1 10 12 15]
Similar Reads
- Python | Numpy matrix.sort() With the help of matrix.sort() method, we are able to sort the values in a matrix by using the same method. Syntax : matrix.sort() Return : Return a sorted matrix Example #1 : In this example we are able to sort the elements in the matrix by using matrix.sort() method. # import the important module 1 min read
- numpy.searchsorted() in Python numpy.searchsorted() function is used to find the indices into a sorted array arr such that, if elements are inserted before the indices, the order of arr would be still preserved. Here, binary search is used to find the required insertion indices. Syntax : numpy.searchsorted(arr, num, side='left', 3 min read
- numpy.sort_complex() in Python numpy.sort_complex() function is used to sort a complex array.It sorts the array by using the real part first, then the imaginary part. Syntax : numpy.sort_complex(arr) Parameters : arr : [array_like] Input array. Return : [complex ndarray] A sorted complex array. Code #1 : # Python program explaini 1 min read
- sort() in Python sort() method in Python sort the elements of a list in ascending or descending order. It modifies the original list in place, meaning it does not return a new list, but instead changes the list it is called on. Example: [GFGTABS] Python a = [5, 3, 8, 1, 2] a.sort() print(a) a.sort(reverse=True) prin 5 min read
- Python NumPy Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. Besides its obvious scientific uses, Numpy can also be used as an efficient 6 min read
- numpy.argmin() in Python The numpy.argmin() method returns indices of the min element of the array in a particular axis. Syntax : numpy.argmin(array, axis = None, out = None) Parameters : array : Input array to work on axis : [int, optional]Along a specified axis like 0 or 1 out : [array optional]Provides a feature to inser 2 min read
- Python List sort() Method The sort() method in Python is a built-in function that allows us to sort the elements of a list in ascending or descending order and it modifies the list in place which means there is no new list created. This method is useful when working with lists where we need to arranged the elements in a spec 4 min read
- numpy.argsort() in Python numpy.argsort() is a function in NumPy that returns the indices that would sort an array. In other words, it gives you the indices that you would use to reorder the elements in an array to be in sorted order. Example: [GFGTABS] Python import numpy as geek a = geek.array([2, 0, 1, 5, 4, 1, 9]) print( 3 min read
- numpy.extract() in Python The numpy.extract() function returns elements of input_array if they satisfy some specified condition. Syntax: numpy.extract(condition, array) Parameters : array : Input array. User apply conditions on input_array elements condition : [array_like]Condition on the basis of which user extract elements 2 min read
- NumPy Tutorial - Python Library NumPy (short for Numerical Python ) is one of the most fundamental libraries in Python for scientific computing. It provides support for large, multi-dimensional arrays and matrices along with a collection of mathematical functions to operate on arrays. At its core it introduces the ndarray (n-dimen 3 min read