dimod icon indicating copy to clipboard operation
dimod copied to clipboard

Add a method for reordering the variables in a sample set

Open arcondello opened this issue 2 years ago • 1 comments

It would be good to have something like

reordered_sampleset = sampleset.reorder_variables(order)

Additional Context This can currently be done "manually"

# Get the samples as an unlabelled array, but with the columns ordered by variable_order
samples_array = sampleset.samples(sorted_by=None)[:, variable_order]

# Construct a new sampleset with that array and variable order, keeping everything else the
# same
reordered_sampleset = dimod.SampleSet.from_samples(
    (samples_array, variable_order),  # the samples array, with the new order
    vartype=sampleset.vartype,  # vartype is the same
    sort_labels=False,  # don't sort the labels
    **sampleset.data_vectors,  # energy, num_occurances, etc are all the same
    )

but it might be nice to have it all bundled into a method

arcondello avatar Apr 19 '23 23:04 arcondello

I second this, it would be great to have this so that pedagogical notebooks intended for youngsters such as this one (see the confusing reordering in cell Out [7]) do not have too complicated code.

dixr avatar Nov 20 '23 09:11 dixr