Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
python
numpy
communitycreator

What is the numpy.msort() function from NumPy in Python?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The msort() function in Python is simply used to return a copy of an array sorted along the first axis.

Syntax

numpy.msort(a)

Parameter value

The msort() function takes a single and mandatory parameter value a, which represents the input array to be sorted.

Return array

The msort() function returns an array of the same type and shape as the input array a passed to it.

Let’s see how to use to it through the following code example.

Example

import numpy as np
# creating lists of numbers
myarray = np.array([[3, 5, 2, 4, 1], [9, 6, 10, 8, 7]])
# implementing the lexsort() function to sort mylist1 first
sortedarray = np.msort(myarray)
print(sortedarray)
Implementing the msort() function

Code explanation

  • Line 1: We import the numpy module.
  • Line 3: We create a 2D array using the array() function
  • Line 7: We implement the msort() function on the array myarray. The result is assigned to a variable sortedarray.
  • Line 9: We print the newly sorted array variable, sortedarray.

RELATED TAGS

function
python
numpy
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring