I want to pairwise and compare (with <=) all elements of two NumPy ndarrays A and B, where both arrays can have arbitrary dimensions m and n, such that the result is an array of dimension m + n.

I know how to do it forgiven dimension of B.

- The scalar: A <= B
- The one-dimensional: A[..., np.newaxis] <= B
- The two-dimensional: A[..., np.newaxis, np.newaxis] <= B

I am trying to insert as many as np.newaxis as there are dimensions in the second array.

Do I have any syntax like np.newaxis * B.ndim, or another way?