human
Rotate all Matrix elements except the diagonal K times by 90 degrees in clockwise direction | Function to print the matrix.
Iterate over the rows.
Iterate over the columns.
Print the value.
Function to perform the swapping of matrix elements in clockwise manner.
Stores the last row.
Stores the last column.
Perform the swaps.
Function to rotate non - diagonal elements of the matrix K times in clockwise direction.
Update K to K % 4.
Iterate until K is positive.
Iterate each up to N / 2 - th row.
Iterate each column from i to N - i - 1.
Check if the element at i , j is not a diagonal element.
Perform the swapping.
Print the matrix.
Driver Code"
Solution in Python:

Give me a code to rotate all Matrix elements except the diagonal K times by 90 degrees in clockwise direction and the other steps required?
assistant
#Here is code to rotate all Matrix elements except the diagonal K times by 90 degrees in clockwise direction and the other steps required.
 def printMat ( mat ) :
	for i in range ( len ( mat ) ) :
		for j in range ( len ( mat [ 0 ] ) ) :
			print ( mat [ i ] [ j ] , end = " ▁ " )
		print ( )
def performSwap ( mat , i , j ) :
	N = len ( mat )
	ei = N - 1 - i
	ej = N - 1 - j
	temp = mat [ i ] [ j ]
	mat [ i ] [ j ] = mat [ ej ] [ i ]
	mat [ ej ] [ i ] = mat [ ei ] [ ej ]
	mat [ ei ] [ ej ] = mat [ j ] [ ei ]
	mat [ j ] [ ei ] = temp
def rotate ( mat , N , K ) :
	K = K % 4
	while ( K > 0 ) :
		for i in range ( int ( N / 2 ) ) :
			for j in range ( i , N - i - 1 ) :
				if ( i != j and ( i + j ) != N - 1 ) :
					performSwap ( mat , i , j )
		K -= 1
	printMat ( mat )
K = 5
mat = [ [ 1 , 2 , 3 , 4 ] , [ 6 , 7 , 8 , 9 ] , [ 11 , 12 , 13 , 14 ] , [ 16 , 17 , 18 , 19 ] ]
N = len ( mat )
rotate ( mat , N , K )