human
Convert a Matrix into another Matrix of given dimensions | Function to construct a matrix of size A * B from the given matrix elements.
Initialize a new matrix.
Traverse the matrix , mat [ ] [ ].
Update idx.
Print the resultant matrix.
Driver Code"
Solution in Python:
assistant
#Here is code to convert a Matrix into another Matrix of given dimensions and the other steps required.
 def ConstMatrix ( mat , N , M , A , B ) :
	if ( N * M != A * B ) :
		return - 1
	idx = 0 ;
	res = [ [ 0 for i in range ( B ) ] for i in range ( A ) ]
	for i in range ( N ) :
		for j in range ( M ) :
			res [ idx // B ] [ idx % B ] = mat [ i ] [ j ] ;
			idx += 1
	for i in range ( A ) :
		for j in range ( B ) :
			print ( res [ i ] [ j ] , end = " ▁ " )
		print ( )
if __name__ == ' _ _ main _ _ ' :
	mat = [ [ 1 , 2 , 3 , 4 , 5 , 6 ] ]
	A = 2
	B = 3
	N = len ( mat )
	M = len ( mat [ 0 ] )
	ConstMatrix ( mat , N , M , A , B )