mardi 5 février 2019

create array of random indices with numpy, without same numbers appearing next to eachother, but allowing duplicates [duplicate]

This question already has an answer here:

In order to implement a genetic algorithm I am trying to produce an array of integers where the same item does not immediately repeat, but where duplicates are allowed . For example [1, 2, 1, 2] would be a valid array, while [1, 1, 2, 2] would not be valid.

I am aware of the solutions presented on : Enforcing "no 2 same contiguous elements" in random list generation, but is there any short way to achieve this using numpy array expressions?




Aucun commentaire:

Enregistrer un commentaire