jeudi 2 juin 2022

Creating a 2d numpy array with certain constraints

I would like to create a 2 dimensional numpy array M of size n,n (a square matrix M that is) with the following constraints:

  1. The sum of each row equals to one
  2. The elements of each row are all between 0 and 1
  3. (Bonus) The value of row i that dominates is located at entry M[i,i].

For example, for a square matrix it would be something like M = np.array([[0.88,0.12],[0.13,0.87]])

  1. Ideally I want the entries of each row to follow some Gaussian like distribution whose peak, for row i, is located at element M[i,i].

In this SO thread a similar question is asked. However, playing with the responses there I was not able to find a way to do it. This is a search problem, and I do understand it might be formulated as an optimization problem. However, I am wondering if these constraints can satisfied without the need of some specialized solver.




Aucun commentaire:

Enregistrer un commentaire