def _init_unit_centers(X, n_clusters, random_state, init):
n_examples, n_features = np.shape(X)<EOL>if isinstance(init, np.ndarray):<EOL><INDENT>n_init_clusters, n_init_features = init.shape<EOL>assert n_init_clusters == n_clusters<EOL>assert n_init_features == n_features<EOL>centers = init<EOL>for cc in range(n_clusters):<EOL><INDENT>centers[cc, :] = centers[cc, :] / np.linalg.norm(centers[cc, :])<EOL><DEDENT>return centers<EOL><DEDENT>elif init == "<STR_LIT>":<EOL><INDENT>labels, inertia, centers, iters = spherical_kmeans._spherical_kmeans_single_lloyd(<EOL>X, n_clusters, x_squared_norms=np.ones((n_examples,)), init="<STR_LIT>"<EOL>)<EOL>return centers<EOL><DEDENT>elif init == "<STR_LIT>":<EOL><INDENT>centers = np.random.randn(n_clusters, n_features)<EOL>for cc in range(n_clusters):<EOL><INDENT>centers[cc, :] = centers[cc, :] / np.linalg.norm(centers[cc, :])<EOL><DEDENT>return centers<EOL><DEDENT>elif init == "<STR_LIT>":<EOL><INDENT>centers = _init_centroids(<EOL>X,<EOL>n_clusters,<EOL>"<STR_LIT>",<EOL>random_state=random_state,<EOL>x_squared_norms=np.ones((n_examples,)),<EOL>)<EOL>for cc in range(n_clusters):<EOL><INDENT>centers[cc, :] = centers[cc, :] / np.linalg.norm(centers[cc, :])<EOL><DEDENT>return centers<EOL><DEDENT>elif init == "<STR_LIT>":<EOL><INDENT>centers = np.random.randn(n_clusters, n_features)<EOL>q, r = np.linalg.qr(centers.T, mode="<STR_LIT>")<EOL>return q.T<EOL><DEDENT>elif init == "<STR_LIT>":<EOL><INDENT>centers = np.zeros((n_clusters, n_features))<EOL>for cc in range(n_clusters):<EOL><INDENT>while np.linalg.norm(centers[cc, :]) == <NUM_LIT:0>:<EOL><INDENT>labels = np.random.randint(<NUM_LIT:0>, n_clusters, n_examples)<EOL>centers[cc, :] = X[labels == cc, :].sum(axis=<NUM_LIT:0>)<EOL><DEDENT><DEDENT>for cc in range(n_clusters):<EOL><INDENT>centers[cc, :] = centers[cc, :] / np.linalg.norm(centers[cc, :])<EOL><DEDENT>return centers<EOL><DEDENT>
Initializes unit norm centers.

    Parameters
    ----------
    X : array-like or sparse matrix, shape=(n_samples, n_features)

    n_clusters : int, optional, default: 8
        The number of clusters to form as well as the number of
        centroids to generate.

    random_state : integer or numpy.RandomState, optional
        The generator used to initialize the centers. If an integer is
        given, it fixes the seed. Defaults to the global numpy random
        number generator.

    init:  (string) one of
        k-means++ : uses sklearn k-means++ initialization algorithm
        spherical-k-means : use centroids from one pass of spherical k-means
        random : random unit norm vectors
        random-orthonormal : random orthonormal vectors
        If an ndarray is passed, it should be of shape (n_clusters, n_features)
        and gives the initial centers.