# Changing Elements Problem in Combinations of Any Array

Assume that I’ve created an permutation array:

``````sample = [0,0],[1,0],[0,1]
Per_arr = [[α,β] for α in sample for β in sample]
``````
``````# Output
9-element Vector{Vector{Vector{Int64}}}:
[[0, 0], [0, 0]]
[[0, 0], [1, 0]]
[[0, 0], [0, 1]]
[[1, 0], [0, 0]]
[[1, 0], [1, 0]]
[[1, 0], [0, 1]]
[[0, 1], [0, 0]]
[[0, 1], [1, 0]]
[[0, 1], [0, 1]]
``````

When I try to change element of `sample` matrices,

``````changed_arr = Per_arr[2]
chg[2][1] = 0
``````
``````# Output
9-element Vector{Vector{Vector{Int64}}}:
[[0, 0], [0, 0]]
[[0, 0], [0, 0]]
[[0, 0], [0, 1]]
[[0, 0], [0, 0]]
[[0, 0], [0, 0]]
[[0, 0], [0, 1]]
[[0, 1], [0, 0]]
[[0, 1], [0, 0]]
[[0, 1], [0, 1]]
``````

All the other elements that are the same as changed_arr are changed! I want to change just specific elements of array while the other remains same. In conclusion, elements of permutated array are not individual, they are coupling elements. When I change the one element, the other same element that I changed one will be change.

How is this possible? What is the basic/efective solution?

you need `Per_arr = [[copy(α),copy(β)] for α in sample for β in sample]`

1 Like