Using NumPy, it is possible to create arrays of any dimension and shape, and perform operations on them with ease. Sorting is an essential operation when dealing with arrays of data, and NumPy provides efficient sorting functions that can be applied to arrays of any size. In this article, we will discuss how to create a random vector of size 5 and sort it using NumPy.

#### 1. By "random module" and "sort()" method:

`random.rand()`

is a function in NumPy that generates an array of random numbers with a specified shape. The function takes one or more arguments that specify the dimensions of the output array. `sort()`

is a method in NumPy that sorts the elements of an array in ascending or descending order.

You can use NumPy’s `random.rand()`

function to generate a NumPy array of random numbers and the **sort()** method to sort the array in ascending order. Here’s an example given below:

#### 2. By "argsort()" method:

`argsort()`

is a method in NumPy that returns the indices that would sort an array in ascending order.

You can use NumPy’s `random`

module to generate array of random numbers, the `argsort()`

method to return the indices that would sort the array, and array indexing to sort the array based on the sorted indices.

Here’s an example given below:

#### 3. By "sorted()" function:

Instead of using NumPy’s sorting methods, you can use Python’s built-in `sorted()`

function to sort the vector in ascending order. Then, simply use **print()** function to print values

Here’s an example given below: