human
Count sub | function to count all sub - arrays divisible by k.
create auxiliary hash array to count frequency of remainders.
Traverse original array and compute cumulative sum take remainder of this current cumulative sum and increase count by 1 for this remainder in mod array.
as the sum can be negative , taking modulo twice.
Initialize result.
Traverse mod.
If there are more than one prefix subarrays with a particular mod value ..
add the subarrays starting from the arr [ i ] which are divisible by k itself.
function to count all sub - matrices having sum divisible by the value 'k  .
Variable to store the final output.
Set the left column.
Set the right column for the left column set by outer loop.
Calculate sum between current left and right for every row 'i  .
Count number of subarrays in temp having sum divisible by ' k ' and then add it to 'tot_count  .
required count of sub - matrices having sum divisible by 'k  .
Driver Code"
How can the above be solved in Python?

Can you provide a code to count sub and the other steps required?
assistant
#Here is code to count sub and the other steps required.
 def subCount ( arr , n , k ) :
	mod = [ 0 ] * k ;
	cumSum = 0 ;
	for i in range ( 0 , n ) :
		cumSum = cumSum + arr [ i ] ;
		mod [ ( ( cumSum % k ) + k ) % k ] = mod [ ( ( cumSum % k ) + k ) % k ] + 1 ;
	result = 0 ;
	for i in range ( 0 , k ) :
		if ( mod [ i ] > 1 ) :
			result = result + int ( ( mod [ i ] * ( mod [ i ] - 1 ) ) / 2 ) ;
	result = result + mod [ 0 ] ;
	return result ;
def countSubmatrix ( mat , n , k ) :
	tot_count = 0 ;
	temp = [ 0 ] * n ;
	for left in range ( 0 , n - 1 ) :
		for right in range ( left , n ) :
			for i in range ( 0 , n ) :
				temp [ i ] = ( temp [ i ] + mat [ i ] [ right ] ) ;
			tot_count = ( tot_count + subCount ( temp , n , k ) ) ;
	return tot_count ;
mat = [ [ 5 , - 1 , 6 ] , [ - 2 , 3 , 8 ] , [ 7 , 4 , - 9 ] ] ;
n = 3 ;
k = 4 ;
print ( " Count ▁ = ▁ { } " . format ( countSubmatrix ( mat , n , k ) ) ) ;