Finding the minimum
and maximum
values in a NumPy 2D array can provide valuable insights into the data and help us perform various operations such as data normalization, image processing, and data analysis. For this reason, there are various methods that help you in finding the minimum and maximum values of the 2D array. In this thread, we will discuss some techniques that demonstrate, how to create an array and find its minimum and maximum values.
1. By using "random.randit()" , "amin()" , "amax()":
-
The NumPy’s
random.randint()
function is used to generate random integers between specified low and high values, inclusive. -
amin()
function is used to return the minimum value along a specified axis of a NumPy array. -
amax()
function is used to return the maximum value along a specified axis of a NumPy array.
You can used numpy.random.randint()
function to create (10x10) array with random integer values and then finding the minimum and maximum values by using numpy.amin()
and numpy.amax()
functions respectively.
2. Using "random.normal()":
The NumPy’s random.normal()
function generates an array of random numbers drawn from a normal (Gaussian) distribution with a given mean and standard deviation. To find the minimum and maximum values of a 2D array generated using random.normal()
, you can use the np.amin()
and np.amax()
functions from NumPy.
Here’s an example of how to generate a 2D array of random numbers using random.normal()
and then find the minimum and maximum values:
3. Using `random.uniform()` function:
The NumPy’s random.uniform()
function generates an array of random numbers drawn from a uniform distribution over a specified interval. To find the minimum and maximum values of a 2D array generated using random.uniform()
, you can use the np.amin()
and "np.amax() functions from NumPy.
Here’s an example of how to generate a 2D array of random numbers using random.uniform()
and then find the minimum and maximum values.