Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method for reordering the variables in a sample set #1325

Open
arcondello opened this issue Apr 19, 2023 · 1 comment
Open

Add a method for reordering the variables in a sample set #1325

arcondello opened this issue Apr 19, 2023 · 1 comment
Labels
feature-request/enhancement New feature or request

Comments

@arcondello
Copy link
Member

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 arcondello added the feature-request/enhancement New feature or request label Apr 19, 2023
@dixr
Copy link

dixr commented Nov 20, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants