Numpy Amin Function

PythonPythonBeginner
Practice Now

Introduction

This lab will cover the basics of using the numpy.amin() function of the NumPy library. The numpy.amin() function is a statistical function that is used to return the smallest element of an array or smallest element along an axis. This lab will demonstrate how to use the function, its parameters, and what it returns.

VM Tips

After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.

Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.

If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL python(("`Python`")) -.-> python/BasicConceptsGroup(["`Basic Concepts`"]) python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"]) python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"]) python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"]) numpy(("`NumPy`")) -.-> numpy/ArrayBasicsGroup(["`Array Basics`"]) numpy(("`NumPy`")) -.-> numpy/IndexingandSlicingGroup(["`Indexing and Slicing`"]) python/BasicConceptsGroup -.-> python/booleans("`Booleans`") python/DataStructuresGroup -.-> python/lists("`Lists`") python/DataStructuresGroup -.-> python/tuples("`Tuples`") python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`") python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`") numpy/ArrayBasicsGroup -.-> numpy/multi_array("`Multi-dimensional Array Creation`") numpy/ArrayBasicsGroup -.-> numpy/data_array("`Data to Array`") numpy/IndexingandSlicingGroup -.-> numpy/bool_idx("`Boolean Indexing`") numpy/IndexingandSlicingGroup -.-> numpy/fancy_idx("`Fancy Indexing`") subgraph Lab Skills python/booleans -.-> lab-86389{{"`Numpy Amin Function`"}} python/lists -.-> lab-86389{{"`Numpy Amin Function`"}} python/tuples -.-> lab-86389{{"`Numpy Amin Function`"}} python/importing_modules -.-> lab-86389{{"`Numpy Amin Function`"}} python/numerical_computing -.-> lab-86389{{"`Numpy Amin Function`"}} numpy/multi_array -.-> lab-86389{{"`Numpy Amin Function`"}} numpy/data_array -.-> lab-86389{{"`Numpy Amin Function`"}} numpy/bool_idx -.-> lab-86389{{"`Numpy Amin Function`"}} numpy/fancy_idx -.-> lab-86389{{"`Numpy Amin Function`"}} end

Import Required Libraries

The first step is to import the required library which is NumPy.

import numpy as np

Create Input Array

The second step is to create an input array.

a = np.array([[2,15,20],[80,43,31],[22,43,10]])

Find Minimum Element

The third step is to find the minimum element in the array using numpy.amin(). This function will return the smallest element in the array.

np.amin(a)

The output will be:

2

Find Minimum Element Among Rows

The fourth step is to find the minimum element among the rows of the array using numpy.amin(). This function with an additional parameter of axis=0 will return an array of smallest element in each row of the array.

np.amin(a, axis=0)

The output will be:

array([2, 15, 10])

Find Minimum Element Among Columns

The fifth step is to find the minimum element among columns of the array using numpy.amin(). This function with an additional parameter of axis=1 will return an array of smallest element in each column of the array.

np.amin(a, axis=1)

The output will be:

array([ 2, 31, 10])

Find Minimum Element with Optional Parameters

In this step, we will use the where and initial optional parameters of numpy.amin() to find the minimum element in an array.

np.amin(a, where=[False, True], initial=10, axis=0)

The where parameter is a boolean array that specifies the condition for the minimum value. The initial parameter is the value of the initial minimum value. The output will be:

array([10, 15, 10])

Summary

This lab covered the numpy.amin() statistical function of the NumPy library with its syntax, parameters, and returned values. We covered how to find the minimum element of an array and how to find the minimum element along the rows and columns of an array. We also covered how to use the where and initial optional parameters to find the minimum element of an array.

Other Python Tutorials you may like