def set_states_per_dim(cls, nstates):
        """Sets the number of states per feature.

        This extracts the number of features from `nstates` and compares
        it to the attribute `nfeatures`. If it doesn't match, an exception
        is thrown. If the `nfeatures` attribute is None, `nfeatures` is set
        to the extracted value.

        Parameters
        ----------
        nstates : array_like, shape (`nfeatures`,)
            The number of states per features

        Raises
        ------
        ValueError
            If the array is not a vector of length `nfeatures`.

        """
        nstates = np.asarray(nstates, dtype=cls.dtype)
        dim = nstates.size
        if dim == 1:
            nstates.shape = (1,)

        if cls.nfeatures is None:
            cls.nfeatures = nstates.shape[0]

        if nstates.ndim != 1 or nstates.shape[0] != cls.nfeatures:
            raise ValueError("Array 'nstates' must be a vector of length %d." % cls.nfeatures)

        cls.states_per_dim = nstates