Write a NumPy program to create random vector of size 15 and replace the maximum value by -1.
import numpy as np x = np.random.random(15) print("Original array:") print(x) x[x.argmax()] = -1 print("Maximum value replaced by -1:") print(x)
Sample Output:
Original array: [ 0.04921181 0.83545304 0.4394982 0.81889845 0.8022234 0.46176053 0.95785815 0.86968759 0.35100099 0.00107607 0.4330148 0.56632168 0.57764716 0.09226267 0.01710047] Maximum value replaced by -1: [ 0.04921181 0.83545304 0.4394982 0.81889845 0.8022234 0.46176053 -1. 0.86968759 0.35100099 0.00107607 0.4330148 0.56632168 0.57764716 0.09226267 0.01710047]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer