def randorth(shape): from scipy.linalg import sqrtm, inv assert len(shape) == 2 w = np.random.normal(0, size=shape) w = w.dot(inv(sqrtm(w.T.dot(w)))) return G.sharedf(w) # Softmax function