Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

if you want use reshape():

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

or directly:

import numpy as np
arr=np.ones(shape=(3,3))

or from another matrix:

import numpy as np
arr1=np.array([[1,2,3],[4,5,6],[7,8,9]])
arr2=np.ones_like(arr1)

read documentations (link)

shape: Shape of the new array, e.g., (2, 3) or 2.

if you want 1 instead of 1. set argumant dtype = int

dtype: The desired data-type for the array The default, None, means

over 4 years ago · Santiago Trujillo Report

0

What about this:

>>> np.ones((3,3))
array([[1., 1., 1.],
       [1., 1., 1.],
       [1., 1., 1.]])

>>> np.ones((3,3)).dtype
dtype('float64')

if You want int

>>> np.ones((3,3), dtype='int')
array([[1, 1, 1],
       [1, 1, 1],
       [1, 1, 1]])
over 4 years ago · Santiago Trujillo Report

0

Try

import numpy as np
np.ones((3,3))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!