Wednesday, July 3, 2024
HomeLanguagesPythonnumpy matrix operations | repmat() function

numpy matrix operations | repmat() function

numpy.matlib.repmat() is another function for doing matrix operations in numpy. It returns Repeat a 0-D, 1-D or 2-D array or matrix M x N times.

Syntax : numpy.matlib.repmat(a, m, n)

Parameters :
a : [array_like] The input array or matrix which to be repeated.
m, n : [int] The number of times a is repeated along the first and second axes.

Return : [ndarray] repeating array.

Code #1 :




# Python program explaining
# numpy.matlib.repmat() function
  
# importing numpy and matrix library
import numpy as geek
import numpy.matlib
  
# creating input array using  
# array function 
in_arr = geek.array([[1, 0, 2], [3, 4, 5]])
print("Input array", in_arr) 
  
# making a new array 
# using repmat() function 
out_mat = geek.matlib.repmat(in_arr, 2, 3
print ("Output repeated matrix : ", out_mat) 


Output :

Input array [[1 0 2]
 [3 4 5]]
Output repeated matrix :  [[1 0 2 1 0 2 1 0 2]
 [3 4 5 3 4 5 3 4 5]
 [1 0 2 1 0 2 1 0 2]
 [3 4 5 3 4 5 3 4 5]]

 

Code #2 :




# Python program explaining
# numpy.matlib.repmat() function
  
# importing numpy and matrix library
import numpy as geek
import numpy.matlib
  
# creating input array using  
# arange function 
in_arr = geek.arange(3)
print("Input array", in_arr) 
  
# making a new array 
# using repmat() function 
out_mat = geek.matlib.repmat(in_arr, 2, 2
print ("Output repeated matrix : ", out_mat) 


Output :

Input array [0 1 2]
Output repeated matrix :  [[0 1 2 0 1 2]
 [0 1 2 0 1 2]]

Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments