vendredi 1 mai 2020

How can I generate a random matrix with two fixed positions in Python?

I am trying to create Matrix of N x N, (4x4 in this case). Where the first and last index are always zero. The Matrix is filled with random 0's and 1's. My current code creates a Matrix but I'm not sure how to fix the two bits and randomly generate a zero or one into the remaining 14 spots.

Example:

mapp = np.matrix('0 1 1 1; 0 1 1 1; 0 1 1 1; 0 0 0 0')

So the ones in the matrix should be randomly placed without placing them in the 1st and last index. This code is part of my Genetic Algorithm code that I'm writing, This is a Map that starts at 0 and finds the optimal path to 15. That is the reason for leaving 0 and 15 index values to zero.




Aucun commentaire:

Enregistrer un commentaire