I think it doesnt work if you are trying to create a pymc3 RandomVariable in the function you are performing scan. If I read it correctly you are trying to create a indexing tensor using Categorical distribution, but I think an easier way is either rewrite the scan with categorical into a distribution, or more simple do p_high.argmax() instead.