How can I optimize sampling rate in a matrix based Bayesian Model?

The error you mention is likely coming from numpy or scipy, not from pytensor. You cannot use numpy functions on symbolic pytensor variables (or random variables, which are the same thing).