w3resource logo
Python Exercises

Python NumPy: Create a 3x3 matrix with values ranging from 2 to 10

Python NumPy: Array Object Exercise-3 with Solution

Write a Python program to create a 3x3 matrix with values ranging from 2 to 10.

Sample Solution:-

Python Code:


import numpy as np
x =  np.arange(2, 11).reshape(3,3)
print(x)

Sample Output:

[[ 2  3  4]                                                             
 [ 5  6  7]                                                             
 [ 8  9 10]]

Python Code Editor:

import numpy as np
x =  np.arange(2, 11).reshape(3,3)
print(x)

Improve this sample solution and post your code through Disqus