# Number of matrices with entries in $\{0,1,2\}$ with prescribed row and column sums

I want to count the number of $\ell_1\times\ell_2$ matrices with entries in $\{0,1,2\}$ and prescribed sum of entries for each row and column.

For example, there are three $2\times 2$ matrices with row and column sums equal to 2: $$\begin{pmatrix}2&0\\0&2\end{pmatrix},\begin{pmatrix}0&2\\2&0\end{pmatrix},\begin{pmatrix}1&1\\1&1\end{pmatrix}$$

There are 21 $3\times 3$ matrices with row and column sums equal to 2 - not listed here, but you can check in GAP using the following command:

gap> R:=Filtered(Tuples([0,1,2],3),r->Sum(r)=2);
gap> Q:=Filtered(Tuples(R,3),M->ForAll(TransposedMat(M),r->Sum(r)=2));
gap> Size(Q);


I also found a paper by Wang and Zhang (1997) for the number of matrices with entries in $\{0,1\}$ with prescribed row and column sums, so I am wondering how I can extend it to $\{0,1,2\}$.