In case of differential evolution, during mutation, the formula that is used most often is

```
arr[a] = (arr[b] + M * (arr[c] - arr[d])) % arr.shape[1]
```

Where

`arr`

is a 2d array consisting of non-negative integers such that all elements in each row are unique,

`a`

represents each row of `arr`

,

`M`

is the mutation constant ranging between 0 and 2 and

`b`

, `c`

and `d`

are 3 unique random numbers.

However, on using this formula, I see that `arr[a]`

has duplicate values based on the values of `arr[b]`

, `arr[c]`

and `arr[d]`

. I wish to have only unique numbers in `arr[a]`

. How is it possible using Numpy?

e.g.

```
arr[a] = [2, 8, 4, 9, 1, 6, 7, 3, 0, 5]
arr[b] = [3, 5, 1, 2, 9, 8, 0, 6, 7, 4]
arr[c] = [2, 3, 8, 4, 5, 1, 0, 6, 9, 7]
arr[d] = [6, 1, 9, 2, 7, 5, 8, 0, 3, 4]
```

On applying the formula, `arr[a]`

becomes `[9, 7, 0, 4, 7, 4, 2, 2, 3, 7]`

. But I want it to have only unique numbers between `0`

and `arr.shape[1]`

. I am open to modifying the mutation function if needed if M, arr[b], arr[c] and arr[d] are all used meaningfully.

This is a rather different approach to the problem, but since you seem to be working with permutations, I am not sure numerical differences are that meaningful. You can however see the problem in terms of permutations, that is, reordering of vectors. Instead of the difference between two vectors, you may consider the permutation that takes you from one vector to the other, and instead of the addition of two vectors, you may consider applying a permutation to a vector. If you want to have an

`M`

parameter, maybe that could be the number of times you apply the permutation? (assuming that is a non-negative integer)Here is the basic idea of how you could implement this:

Since you are working with many vectors arranged in a matrix, you may prefer vectorized versions of the above functions. You can have that with something like this (here I assume M is a fixed parameter for the whole algorithm, not per individual):