def _random_stochastic_matrix(m, n, k=None, sparse=False, format='csr', random_state=None):
 if (k is None):
  k = n
 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
 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

def _random_stochastic_matrix ( m , n , k = None , sparse = False , format = 'csr' , random_state = None ) : if ( k is None ) : k = n 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 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
generate a "non-square stochastic matrix" of shape .