Skip to main content
added 12 characters in body
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

I'm trying to simplify a table, for instance

{{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}}

{{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}}

Here the first column is the "weight" of the corresponding vector in the second column. 

In the specific problem, the ordering of the entries in the vectors in the second column do not matter, so these can be sorted. I then want to gather the vectors, such that ones that are equivalent only appear once. In the process, I want to sum the weights. For instance, in the above example, the result would be

{{2, {4, 2, 0}}, {-1, {3, 3, 0}}

{{2, {4, 2, 0}}, {-1, {3, 3, 0}}

Any help would be greatly appreciated!

I'm trying to simplify a table, for instance

{{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}}

Here the first column is the "weight" of the corresponding vector in the second column. In the specific problem, the ordering of the entries in the vectors in the second column do not matter, so these can be sorted. I then want to gather the vectors, such that ones that are equivalent only appear once. In the process, I want to sum the weights. For instance, in the above example, the result would be

{{2, {4, 2, 0}}, {-1, {3, 3, 0}}

Any help would be greatly appreciated!

I'm trying to simplify a table, for instance

{{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}}

Here the first column is the "weight" of the corresponding vector in the second column. 

In the specific problem, the ordering of the entries in the vectors in the second column do not matter, so these can be sorted. I then want to gather the vectors, such that ones that are equivalent only appear once. In the process, I want to sum the weights. For instance, in the above example, the result would be

{{2, {4, 2, 0}}, {-1, {3, 3, 0}}

Any help would be greatly appreciated!

Source Link

Sorting a table of vectors with weights

I'm trying to simplify a table, for instance

{{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}}

Here the first column is the "weight" of the corresponding vector in the second column. In the specific problem, the ordering of the entries in the vectors in the second column do not matter, so these can be sorted. I then want to gather the vectors, such that ones that are equivalent only appear once. In the process, I want to sum the weights. For instance, in the above example, the result would be

{{2, {4, 2, 0}}, {-1, {3, 3, 0}}

Any help would be greatly appreciated!