I have a tensor with multinomial probabilities. Each vector (in my example below is 1x3) inside the tensor represent multinomial probability distribution for 1 random variable:
I want to sample from the multinomial probability distribution tensor of random variables.
For example, this is the tensor (MxNxIxJx3) with the multinomial probabilities:

[[w_00ij0, w_00ij1, w_00ij2], … [w_0Nij0, w_0Nij1, w_0Nij2],
…                                       …
[w_M0ij0, w_M0ij1, w_M0ij2], … [w_MNij0, w_MNij1, w_MNij2]]

This the tensor I want to sample (MxNxIxJ)  from the above distribution:

[[x_00ij], … [x_0Nij,],
…
[x_M0ij], … [x_MNij]]

when (for example):

P(x_mnij=0) = w_mnij0
P(x_mnij=1) = w_mnij1
P(x_mnij=2) = w_mnij2

I couldn’t find a way to do it fast (without running all over the tensor).