| by Arround The Web | No comments

## Numpy Amin Method

NumPy is an interactive Python package that refers to “Numeric Python”. It is used in the handling of random numbers. NumPy has basic, mathematical, string, and statistical functions.

NumPy Amin() function is one of the Statistical functions of NumPy. It is used to return the minimum value of the NumPy array or the smallest value along the axis (row-wise or column-wise) when required. In this guide, we will discuss finding the smallest element in a NumPy array using the amin() method.

## Syntax

The following syntax is used to implement the NumPy Amin() method:

Numpy.amin (Arr, Axis, Out, Keepdims=< >, Initial=< >)

## Arguments

The following four optional and non-optional parameters are used:

Arr = This argument indicates a NumPy array or input data to be used.

Axis = This argument indicates an axis means row and column along which min value has to be calculated.

Out = This argument indicates an alternative array in which results are saved or placed. It is an optional parameter.

Keepdims = If the value of this argument is set to True, then the reduced axis is left as dimensions with size one.

Initial = This argument indicates the highest or maximum value of the NumPy array. It is a scalar and optional parameter.

## Return Values

The amin() function returns two types of minimum values:

1. Scalar: When the axis is None
2. The array of ndim-1: When the axis is given

• A NumPy array consumes less memory space.
• It is used to create n-dimension arrays.
• Provides better runtime speed in Python.
• Numpy arrays are used in solving linear equations.
• It supports multiplication and addition operations.
• It is used for data analysis.

• Insertion and deletion operations become expensive due to data stored in a contiguous location.

## Example No. 1

Find the minimum value and minimum axis of the array.

In the first instance, we will get the array’s minimum value and the minimum row of the array. First, we have imported the NumPy library of Python as np. Without importing, its code will not execute. Then we have assigned “arr” random values i-e [26, 27, 28] & [55, 56, 57] according to syntax. After that, we printed the given array “arr” to display the output. The print() function is used to show the output. Then printed, the minimum value from the array is by calling the np.amin((arr)) function. Finally, we printed the minimum value among axis row-wise by calling np.amin(arr,0) function. Here, we pass 0 as the parameter of the amin() function.

Here is the output of the previous program in which we are left with minimum values and minimum rows.

In this outcome, we have a minimum value of 26, and the minimum row of the array is [26, 27, 28].

## Example No. 2

Determine the smallest value of the one-dimensional array.

To clarify more concepts about the np amin() method, here is another example in which we have implemented a program to find the minimum value of the one-dimensional array. Importing the NumPy library of Python is the main step. Then in the second statement, initialize the array by passing random numbers by calling np.Array() function. We have passed elements [17, 18, 19] to the array to find its minimum value. In the third statement, we initialized “min_ele”, which represents the minimum element.

Further, we invoke the np.amin(array) method, which gives us a minimum element of the array. In the fourth statement, the print() statement displays the array’s values. In the end, the print statement shows the smallest element of the defined array. The “min_ele” gives the minimum value in the outcome.

Here is the result of the previously executed program:

In the result of the fourth statement, we get [17 18 19], which is the defined array. Similarly, in the result of the fifth statement, we get the minimum value of the given array, which is 17.

## Example No. 3

Acquire the minimum values in a Multidimensional array.

In this case, we would implement the np.amin() function to get the minimum values of the Multidimensional Array. Multidimensional array means arrays of different dimensions or shapes, for example, 6*3, 5*3.

In the first step, we imported the Python library NumPy as np which is mandatory to mention. Then assign the variable “arr” to different arrays with random elements using np.Array() function i-e  ([(21, 3, 36), (42, 7, 48), (81, 48, 30), (61, 67, 98)]). In the next statement, the print(arr) function represents the specified elements of each array. The print() statement is being called to display the matrix/size of the array, which represents the size of columns and rows of each array. This is done by calling the np.shape(arr) function. The print statement is again applied to display the minimum value from the entire array by calling the np.amin((arr)) method. In the next statement, “m” is initialized as a variable by passing it to the np.amin(arr, axis=1) function. We have passed arguments “arr” and axis “1”, which contain the minimum value of each row. Then the output is displayed by using a print statement. Moreover, “n” is initialized as a variable. In the second case, we have given “arr” and axis “0” as the function’s arguments, which contain the minimum value of each column by calling amin(arr, axis=0) function and printing the output with the help of the print() method.

The result of implemented code is given in which we have the elements of a required multidimensional array, the matrix of the array and minimum value of the array.

## Conclusion

In this article, we have talked about the Numpy.amin() function and its syntax, parameters, and return values which have taught us how to implement the Python Numpy programs using this function. We have also covered its advantages and disadvantages, through which we learn about the scope of NumPy and its functions. We executed different programs to see the functionality of the np.amin() method and how it is used in Python. In addition, we have obtained the smallest value of the one-dimensional array and multidimensional array by using the amin() method.

Source: linuxhint.com