Q:

Write a NumPy program to create a 5x5 matrix with row values ranging from 0 to 4

0

Write a NumPy program to create a 5x5 matrix with row values ranging from 0 to 4

All Answers

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

import numpy as np
x = np.zeros((5,5))
print("Original array:")
print(x)
print("Row values ranging from 0 to 4.")
x += np.arange(5)
print(x)
Sample Output:
Original array:                                                        
[[ 0.  0.  0.  0.  0.]                                                 
 [ 0.  0.  0.  0.  0.]                                                 
 [ 0.  0.  0.  0.  0.]                                                 
 [ 0.  0.  0.  0.  0.]                                                 
 [ 0.  0.  0.  0.  0.]]                                                
Row values ranging from 0 to 4.                                        
[[ 0.  1.  2.  3.  4.]                                                 
 [ 0.  1.  2.  3.  4.]                                                 
 [ 0.  1.  2.  3.  4.]                                                 
 [ 0.  1.  2.  3.  4.]                                                 
 [ 0.  1.  2.  3.  4.]]

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