Here rays are called lines.
Call $M(a_1,a_2)$ the number for matrices of length $a_1$ and height $a_2$, made of $0$ and $1$, having neither null vector nor null co-vector. In other words any line (row or column) contains at least one $1$.

**QUESTION 1** : How to count them?

**QUESTION 2** : Same as above in higher dimensions.

It looks like a standard problem:

For example $M(1,p) =1$ , $M(2,p) = 3^p -2$ , $M(3,p) = 7^p -3.3^p +3$ , $M(4,p) = 15^p -4.7^p + 6.3^p -4$ The closed formula being clear but I have no clean proof for it.

Question for higher dimensions;
for a cube $M(a_1,a_2,a_3)$ in $0-1$ ($2^{a_1a_2a_3}$ of them) with no null lines (in any of the three directions ).

For example $M(2,2,2) = 35$ (by hand).

Is there a closed formula for M(a_1,a_2,...a_k) in particular k = 3,4?

It seems that things change a lot when passing from k=2 to k=3, Even for k=3 and constraining last dimension to 2 : $M(a_1,a_2,2)=? $