Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy sort

import numpy as np

arr = np.array([3, 2, 0, 1])
print(np.sort(arr))
# output [0 1 2 3]

arr = np.array(['banana', 'cherry', 'apple'])
print(np.sort(arr))
# output ['apple' 'banana' 'cherry']

arr = np.array([True, False, True])
print(np.sort(arr))
# output [False  True  True]

arr = np.array([[3, 2, 4], [5, 0, 1]])
print(np.sort(arr))
# output
# [[2 3 4]
#  [0 1 5]]
Comment

numpy sort

>>> a = np.array([[1,4],[3,1]])
>>> np.sort(a)                # sort along the last axis
array([[1, 4],
       [1, 3]])
>>> np.sort(a, axis=None)     # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0)        # sort along the first axis
array([[1, 1],
       [3, 4]])
Comment

numpy array sorting

a = np.array([[1,4],[3,1]])
>>> np.sort(a)                # sort along the last axis
array([[1, 4],
       [1, 3]])
>>> np.sort(a, axis=None)     # sort the flattened array
array([1, 1, 3, 4])
>>> np.sort(a, axis=0)        # sort along the first axis
array([[1, 1],
       [3, 4]])
Comment

How to sort numpy array

np.sort(arr)
array([1, 2, 3, 4, 5, 6, 7, 8])
Comment

numpy.sort

a = np.array([[1,4], [3,1]])
>>> a.sort(axis=1)
>>> a
array([[1, 4],
       [1, 3]])
>>> a.sort(axis=0)
>>> a
array([[1, 3],
       [1, 4]])
Comment

How to sort numpy array

arr=[1,4,2,6,3,5,8,7]
np.sort(arr)
array([1, 2, 3, 4, 5, 6, 7, 8])
Comment

Sort array numpy


arr = np.array([2, 1, 5, 3, 7, 4, 6, 8])
np.sort(arr)
Comment

PREVIOUS NEXT
Code Example
Python :: pytest fixture 
Python :: import sentence transformers 
Python :: python power of e 
Python :: Replace an item in a python list 
Python :: euclidean distance 
Python :: loading bar in python 
Python :: sum up list python 
Python :: pandas replace values from another dataframe 
Python :: include app in django project 
Python :: greater and less than in python 
Python :: django middleware 
Python :: reaction role discord.py 
Python :: class method in python 
Python :: torch.utils.data.random_split(dataset, lengths) 
Python :: color reverse 
Python :: cache-control no cache django 
Python :: pandas df number of columns 
Python :: how to find the last element of list in python 
Python :: Python NumPy split Function Syntax 
Python :: how to use djoser signals 
Python :: models django 
Python :: run python on android 
Python :: how to find ascii value by python 
Python :: float field vs decimal field in django models 
Python :: python nested object to dict 
Python :: @property python 
Python :: floor function in python 
Python :: problem solving with python 
Python :: python how to check if string is empty 
Python :: multiple values in a dictionary python 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =