Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a 3 X 3 Matrix will all ones in it using NumPy

I am learner , bit stuck with it
Not getting how do I create below 3 X 3 matrix will all 1 ones in it

  1 , 1 , 1
  1 , 1 , 1
  1 , 1 , 1

My code :

import numpy as np
arr=np.ones(np.full(1)).reshape(3,3)
arr

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Slightly change to the solution of author : user1740577

The user is expecting only integer value and not decimal values

By adding dtype=int the OP’s expected output can be achieved

Code :

import numpy as np
np.ones((3,3),dtype=int)

Expected output :

array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading