4
$\begingroup$

Say I have a nested Association like this one:

assc = <|1-><|a1-><|opt->0.734149,fit->0.56074|>,a2-><|opt->-0.268146,fit->-0.536405|>,a3-><|opt->23.1298,fit->12.5986|>|>,2-><|a1-><|opt->9.53617*10^-8,fit->0.337033|>,a2-><|opt->-0.0000357894,fit->-0.250143|>,a3-><|opt->2.76778*10^-6,fit->-7.54487|>|>,3-><|a1-><|opt->0.80264,fit->0.526605|>,a2-><|opt->-0.0159458,fit->-0.646664|>,a3-><|opt->45.9309,fit->-12.3689|>|>,4-><|a1-><|opt->0.913804,fit->0.741119|>,a2-><|opt->-0.145981,fit->-0.808445|>,a3-><|opt->11.7184,fit->2.29814|>|>,5-><|a1-><|opt->0.702291,fit->0.528957|>,a2-><|opt->-0.0902689,fit->-0.25787|>,a3-><|opt->11.4746,fit->12.7903|>|>|>

whose Dataset view looks like this: enter image description here

I'd like to Transpose the Dataset to rearrange its levels as the similar operation over its values:

Transpose[(assc //. assc : Association[v__] :> Values[assc]), {1, 3, 2}]

However, I find such Transpose operation is not possible over an Association:

Transpose[assc, {1, 3, 2}]

enter image description here

What is the proper way in Mathematica to do that?

$\endgroup$
3
  • $\begingroup$ You could try Transpose /@ assc instead. $\endgroup$
    – Carl Woll
    Feb 25, 2018 at 17:19
  • $\begingroup$ Thanks @CarlWoll. The case I raised is actually a simple one: I need some workaround for higher dimensional datasets. And I just learnt the current Association is actually atomic, which might cause this more difficult. $\endgroup$
    – sunt05
    Feb 25, 2018 at 22:57
  • 4
    $\begingroup$ Dataset supports Transpose, you might want to try assc // Dataset // #[;; , Transpose] & // Normal. $\endgroup$
    – Silvia
    Nov 10, 2018 at 6:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.