randomly choose pair (i, j) with probability P[i, j] given stochastic matrix P
Here's a simple algorithm in python that does what you are expecting.
Let's take for example a single dimension array P equal to [0.1,0.3,0.4,0.2]. The logic can be extended to any number of dimensions.
Now we set each element to the sum of all the elements that precede it:
P => [0, 0.1, 0.4, 0.8, 1]
Using a random generator, we generate numbers that are between 0 and 1. Let's say x = 0.2.
Using a simple binary search, we can determine that x is between the first element and the second element. We just pick the first element for this value of x.
If you look closely, the chance that 0 =< X  < 0.1 is 0.1. The chance that 0.1 =< x < 0.4 is 0.3 and so on.
For the 2D array, it is better to convert it to a 1D array, even though, you should be able to implement a 2D array binary search algorithm.
I have numpy two dimension array P such that P[i, j] >= 0 and all P[i, j] sums to one. How to choose pair of indexes (i, j) with probability P[i, j] ?
EDIT: I am interested in numpy build function. Is there something for this problem? May be for one dimensional array?