我们有以下矩阵result
:
result =
Columns 1 through 13
3 1 1 1 1 1 6 2 3 6 2 1 6
4 3 3 5 7 5 10 10 4 10 6 9 8
6 4 4 7 9 7 0 0 0 0 0 0 0
10 5 5 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 10 3 10 3 8 8 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
其列唯一元素索引大小为(不含零):
Indexes of result:
Columns 1 through 13
4 4 4 4 3 3 2 2 2 2 2 2 2
Columns 14 through 25
2 1 1 1 1 1 1
我想执行以下场景:从第一列开始,我们希望将每个非唯一值限制为仅在矩阵中出现一次。因此,以 col1 作为起点,矩阵的其余部分应重新排列为:
result =
Columns 1 through 13
3 1 1 1 1 1 0 2 0 0 2 1 0
4 0 0 5 7 5 0 0 0 0 0 9 8
6 0 0 7 9 7 0 0 0 0 0 0 0
10 5 5 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 0 0 0 0 8 8 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 2 2 4 3 3 0 1 0 0 1 2 1
Columns 14 through 25
2 0 0 0 0 1 1
现在我们看到 col4 有最独特的元素,所以我们考虑它的值继续第二次重新排列,结果是:
result =
Columns 1 through 13
3 0 0 1 0 0 0 2 0 0 2 0 0
4 0 0 5 0 0 0 0 0 0 0 9 0
6 0 0 7 9 0 0 0 0 0 0 0 0
10 0 0 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
2 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 0 0 4 1 0 0 1 0 0 1 1 0
Columns 14 through 25
1 0 0 0 0 1 1
根据需要多次执行此操作,在该示例中,col5 和 col8 再执行两次,我们达到了预期的结果:
result =
Columns 1 through 13
3 0 0 1 0 0 0 2 0 0 0 0 0
4 0 0 5 0 0 0 0 0 0 0 0 0
6 0 0 7 9 0 0 0 0 0 0 0 0
10 0 0 8 0 0 0 0 0 0 0 0 0
Columns 14 through 25
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Indexes of result (without zeros):
Columns 1 through 13
4 0 0 4 1 0 0 1 0 0 0 0 0
Columns 14 through 25
0 0 0 0 0 0 0
执行此操作的最有效方法是什么?我可以看看你的建议吗?
先感谢您。