Generate a "non-square stochastic matrix" of shape (m, n), which
    contains as rows m probability vectors of length n with k nonzero
    entries.

    For other parameters, see `random_stochastic_matrix`.

def _random_stochastic_matrix(m, n, k=None, sparse=False, format='csr',
                              random_state=None):
    """
    Generate a "non-square stochastic matrix" of shape (m, n), which
    contains as rows m probability vectors of length n with k nonzero
    entries.

    For other parameters, see `random_stochastic_matrix`.

    """
    if k is None:
        k = n
    # m prob vectors of dimension k, shape (m, k)
    probvecs = probvec(m, k, random_state=random_state)

    if k == n:
        P = probvecs
        if sparse:
            return scipy.sparse.coo_matrix(P).asformat(format)
        else:
            return P

    # if k < n:
    rows = np.repeat(np.arange(m), k)
    cols = \
        sample_without_replacement(
            n, k, num_trials=m, random_state=random_state
        ).ravel()
    data = probvecs.ravel()

    if sparse:
        P = scipy.sparse.coo_matrix((data, (rows, cols)), shape=(m, n))
        return P.asformat(format)
    else:
        P = np.zeros((m, n))
        P[rows, cols] = data
        return P