
Quick Contact
Python Tutorial
- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Python Panda Tutorial
- Python Pandas Tutorial
- Python Pandas Features
- Advantages and Disadvantages of Python Pandas
- Pandas Library In Python
- Pandas Series To Frame
- Python Dataframeaggregate and Assign
- Pandas Dataframe Describe
- Pandas Dataframe Mean
- Pandas Hist
- Pandas Dataframe Sum
- How to convert Pandas DataFrame to Numpy array
- Pandas Concatenation
- Pandas Shift
- Pandas Rolling
- Data Analysis With Pandas and Python
- How Python Panda Are Helpful For With Data Science
Python Selenium
- Selenium Basics
- Selenium with Python Introduction and Installation
- Navigating links using get method Selenium Python
- Locating Single Elements in Selenium Python
- Locating Multiple elements in Selenium Python
Python Flask Tutorial
Python Django
- How to Install Django and Set Up a Virtual Environment in 6 Steps
- Django MTV Architecture
- Django Models
- Django Views
- Django Templates
- Django Template Language
- Django Project Layout
- Django Admin Interface
- Django Database
- Django URLs and URLConf
- Django Redirects
- Django Cookies and Cookies Handling
- Django Caching
- Types of Caching in Django
- Django Sessions
- Django Forms Handling & Validation
- Django Exceptions & Error-handling
- Django Forms Validation
- Django Redirects
- Django Admin Interface
- Django Bootstrap
- Ajax in Django
- Django Migrations and Database Connectivity
- Django Web Hosting and IDE
- Django Admin Customization
- What is CRUD?
- Django ORM
- Django Request-Response Cycle
- Django ORM
- Making a basic_api with DRF
- Django Logging
- Django Applications
- Difference between Flask vs Django
- Difference between Django vs PHP
Numpy
- Numpy Introduction
- NumPy– Environment Setup
- NumPy - Data Types
- NumPy–Functions
- NumPy Histogram
- numPy.where
- numpy.sort
- NumPyfloor
- Matrix in NumPy
- NumPy Arrays
- NumPy Array Functions
- Matrix Multiplication in NumPy
- NumPy Matrix Transpose
- NumPy Array Append
- NumPy empty array
- NumPy Linear Algebra
- numpy.diff()
- numpy.unique()
- numpy.dot()
- numpy.mean()
- Numpy.argsort()
- numpy.pad()
- NumPyvstack
- NumPy sum
- NumPy Normal Distribution
- NumPylogspace()
- NumPy correlation
- Why we learn and use Numpy?
Tensorflow
- Introduction To Tensorflow
- INTRODUCTION TO DEEP LEARNING
- EXPLAIN NEURAL NETWORK?
- CONVOLUTIONAL AND RECURRENT NEURAL NETWORK
- INTRODUCTION TO TENSORFLOW
- INSTALLATION OF TENSORFLOW
- TENSORBOARD VISUALIZATION
- Linear regression in tensorflow
- Word Embedding
- Difference between CNN And RNN
- Explain Keras
- Program elements in tensorflow
- Recurrent Neural Network
- Tensorflow Object Detection
- EXPLAIN MULTILAYER PERCEPTRON
- GRADIENT DESCENT OPTIMIZATION
Interview Questions & Answers
numpy.sort
Numpy.sort() is a sorting function that helps in arranging the elements of an array in a certain order. Let’s say we want to sort our array in ascending order along the first axis, then numpy.sort() comes to our rescue. Numpy provides four different sorting algorithms: quicksort, heapsort, mergesort, and timsort. We will be discussing these algorithms in great detail while solving some examples. We can choose any of the mentioned algorithms based on the required time and space complexity.
Syntax and Parameters:
Moving ahead, let’s discuss the numpy.sort() function in greater details. The standard syntax for writing this function is as follows:
numpy.sort(a, axis=-1, kind=None, order=None)
The parameters of numpy.sort() are :
-
a: array-like object –
The input array to be sorted.
-
axis: 0, -1 or none –
The axis along which the array has to be sort. If nothing is mentioned, then the array is flattened before sorting. By default, the array is sorted along the last axis. It is denoted by axis = -1.
-
kind: {‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’} –
In numpy, we can choose from any of these sorting algorithms {‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}. By default, the input array will be sorted by using quicksort.
-
order: order of sorting {string or list} –
This parameter specifies the field along which the sorting has to be done. It usually used when we have a field defined array.
Out of the above-mentioned parameters, the first parameter is compulsory. The other parameters are optional and can be used based on the specific requirement. The numpy.sort() function returns a sorted copy of the input array.
Examples to Illustrate numpy.sort
Following are the different examples to illustrate numpy.sort.
Example #1
Program to illustrate sorting along different axes using numpy.sort()
Code:
import numpy as np #creating an array A = np.array([[15, 1], [19, 94]]) print ("The input array is : \n", A) # sorting along the first axis A_sorted = np.sort(A, axis = 0) print ("Sorted array along the first axis : \n", A_sorted) #sorting along the last axis A_sorted = np.sort(A, axis = -1) print ("Sorted array along the last axis : \n", A_sorted) #sorting the flattened axis A_sorted = np.sort(A, axis = None) print ("Sorted array when flattened: \n", A_sorted)
Example #2
Program to illustrate sorting using different sorting algorithms using numpy.sort()
Code:
import numpy as np #creating an array A = np.array([[19, 3], [19, 94]]) print ("The input array is : \n", A) # sorting along the first axis using quicksort A_sorted = np.sort(A, axis = 0, kind = 'quicksort') print ("Sorted array using quicksort : \n", A_sorted) # sorting along the first axis using mergesort A_sorted = np.sort(A, axis = 0, kind = 'mergesort') print ("Sorted array using mergesort : \n", A_sorted) # sorting along the first axis using heapsort A_sorted = np.sort(A, axis = 0, kind = 'heapsort') print ("Sorted array using heapsort : \n", A_sorted) # sorting along the first axis using stable A_sorted = np.sort(A, axis = 0, kind = 'stable') print ("Sorted array using stable : \n", A_sorted)