# Label switching in Hidden Markov Models

**URL:** <https://discourse.pymc.io/t/label-switching-in-hidden-markov-models/9692>\
**Category:** version agnostic\
**Created:** [June 20, 2022, 11:38am UTC](https://discourse.pymc.io/t/label-switching-in-hidden-markov-models/9692 "2022-06-20T11:38:43Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![j\_catulo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/j_catulo/32/4892_2.png) [@j\_catulo](https://discourse.pymc.io/u/j_catulo)\
**Post date:** [June 20, 2022, 4:38pm UTC](https://discourse.pymc.io/t/label-switching-in-hidden-markov-models/9692/2 "2022-06-20T16:38:46Z")

</div>

[This](https://discourse.pymc.io/t/feature-request-handle-label-switching-in-summary-some-ideas/2876/3) post seems to be a good solution, but, as it was said in that post, we would need to overwrite the data in the trace object to swap the sampled values for the switched dimensions. Is it possible to edit the data of an Arviz data structure?

I want to do something like:

```auto
idata2 = idata.copy()
idata2.sel(chain=[1]).posterior['mu'][0][:,0] = idata2.sel(chain=[1]).posterior['mu'][0][:,1]

```

But, by doing this, `idata2` is unaltered.

---

_[View the full topic](https://discourse.pymc.io/t/label-switching-in-hidden-markov-models/9692)._
