Convert a full transmat to the respective p-state and h-state transmats

def full2ph(trans, n_pstates):
    """
    Convert a full transmat to the respective p-state and h-state transmats
    """
    n_hstates = len(trans) / n_pstates

    htrans = np.zeros((n_pstates, n_pstates, n_hstates, n_hstates))
    for pidx1, pidx2 in product(range(n_pstates), range(n_pstates)):
        idx1 = pidx1 * n_hstates
        idx2 = pidx2 * n_hstates
        htrans[pidx1, pidx2] = trans[idx1:idx1 + n_hstates, idx2:idx2 + n_hstates]

    ptrans = normalize(htrans.sum(axis=-1).sum(axis=-1), axis=1)
    htrans = normalize(htrans, axis=3)

    return ptrans, htrans