Q:

Write a NumPy program to create random vector of size 15 and replace the maximum value by -1

0

Write a NumPy program to create random vector of size 15 and replace the maximum value by -1.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now