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.

Solution

import numpy as np
arr = np.random.rand(5, 5)
min_value = arr.min()
arr[arr == min_value] = 0
print("Updated Array:")
print(arr)
Output

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.

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad