numpy.matlib.ones()

This function is used to return a new matrix with the values initialized to ones.

Syntax

snippet
numpy.matlib.ones(shape,dtype,order)

Parameters

It accepts the following parameters.

  1. shape: It is the Tuple defining the shape of the matrix.
  2. dtype: It is the data type of the matrix.
  3. order: It is the insertion order of the matrix.

Return

A matrix is returned with all the entries initialized to 1.

Example

snippet
import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.ones((3,3)))

Output:

Output
[[1. 1. 1.] [1. 1. 1.] [1. 1. 1.]]

Example: initializing integer values

snippet
import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.ones((3,3),int))

Output:

Output
[[1 1 1] [1 1 1] [1 1 1]]

Example: specifying Insertion order

snippet
import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.ones((3,3),int,'C'))

Output:

Output
[[1 1 1] [1 1 1] [1 1 1]]
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents