If you have a loaded dataset, you can convert an ndarray that you know is in centimeters to a YTArray in code_length units like so:
arr_in_code_length = ds.arr(ndarray_in_centimeters, 'cm').to('code_length')
In addition, I don't think you actually need to convert to code_length units if you are passing this array to yt, since yt will internally do the conversion if you hand it a YTArray with units, so just creating an array like this is sufficient:
from yt.units import cm
arr_in_cm = ndarray_in_centimeters * cm
And then pass arr_in_cm to some yt function.
If all you want is the conversion factor from CGS to code length units, then you can inspect ds.length_unit. For example, the conversion from code length units to CGS is ds.length_unit.in_cgs(). There are a number of unit attributes that are attached to datasets (ds.mass_unit, ds.velocity_unit, ds.pressure_unit) that are useful for this sort of thing.
Hope that helps!