Programming Examples
Write a NumPy program to create a 5x5 array with random values and replace the minimum value with 0.
Write a NumPy program to create a 5x5 array with random values and replace the minimum value with 0.
Solutionimport numpy as np
arr = np.random.rand(5, 5)
min_value = arr.min()
arr[arr == min_value] = 0
print("Updated Array:")
print(arr)
▶ RUN Output/ Explanation: np.random.rand(5, 5) generates random values between 0 and 1.
arr.min() finds the minimum value.
The condition arr == min_value locates that value and replaces it with 0.