Ones matrix using numpy.ones() | Linear Algebra using Python

Linear Algebra using Python | Ones Matrix using numpy.ones(): Here, we are going to learn about creating ones matrix using numpy.ones() in Python.
Submitted by Anuj Singh, on May 29, 2020

Ones Matrix - When all the entries of a matrix are one, then it is called as ones matrix. It may be of any dimension (MxN).

Properties:

  • The determinant of the matrix is 1 (when the number of columns and rows are 1, i.e. there is only one element in the matrix) or 0 otherwise.
  • The Rank of any Ones Matrix is 1.

In python, we have an inbuilt function (defined in numpy library) numpy.ones() to define the ones matrix. Here is the code with examples.

Python code for ones matrix using numpy.ones()

# Linear Algebra Learning Sequence
# Ones matrix using numpy.ones() 

import numpy as np

a = np.ones([3,5])
b = np.ones([6,6])
c = np.ones([9,5])

#printing the matrices
print("\n----Ones Matrix (3x5)----\n",a)
print("\n----Ones Matrix (6x6)----\n",b)
print("\n----Ones Matrix (9x5)----\n",c)

Output:

----Ones Matrix (3x5)----
 [[1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]

----Ones Matrix (6x6)----
 [[1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1. 1.]]

----Ones Matrix (9x5)----
 [[1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.