Sparse [k-1]x[k-1] transition frequency matrix

def P(self):
        """Sparse [k-1]x[k-1] transition frequency matrix"""
        if self._P is not None:
            return self._P
        sparse_P = sparse.lil_matrix((self.n, self.n))
        alpha_size = len(self.alphabet)
        bitmask = (self.n-1)  # Mask w/ all bits set hi within (k-1)mer range.
        for fr in range(self.n):
            for a in range(alpha_size):
                to = (fr << 2 | a) & bitmask
                sparse_P[fr, to] = self.transitions[fr, a]
        self._P = sparse_P
        return sparse_P