The above if/else checks avoid a copy when dtype is the same, but that can also be acieved by 

    c_obs = obs.astype(ct, copy=False)
    c_code_book = code_book.astype(ct, copy=False)