In general, PyMC3 operates on theano tensors, so in your code above, you cannot treat z as numpy array.
Vectorizing z into a tensor should do:
with pm.Model() as model:
myBeta = pm.Beta('b', g_0, h_0, shape=K)
pi = pm.Dirichlet('pi', a=alpha*np.ones(K),shape=[N,K])
z = pm.Categorical('z', p=pi, shape=(N, N))
pD = tt.switch(tt.eq(z, z.T), myBeta[z], eps)
y = pm.Bernoulli('D', p=pD, observed=Topology_Data)
Note that:
1, You specify the shape of z, so you dont need a for loop to create it.
2, myBeta[z] broadcast shape = (K,) RV myBeta into the same shape as z with shape = (N, N)
3, I did not reshape the Topology_Data, it still has a shape of (N, N)