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)
▶ 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.

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad