If you want to find the transition matrix, the most common way is to traverse all the elements. It takes a long time and a long code. But with numpy, three lines of code can solve the problem.
If the classification type is known in advance, assuming there are a and b matrices, find the indexes of various types in the a and b matrices, and then cross to obtain the index that meets the category of a certain type of transition matrix, just find the number directly.
However, remember flatten().
pos1=np.where(a==category1)
pos2=np.where(b==category2)
info=np.intersect1d(pos1,pos2).size