Transpose dictionary

It seems like what you want, by definition, is a copy of every element of dict? It’s just a question of what data structure you want to store the copy into.

I used d′[t, f], i.e. a tuple-keyed dictionary, because that’s what you said you wanted. Instead, it seems you want d′[t][f], i.e. a dictionary of vectors? (This has the same asymptotic complexity, but of course the constant factors and the memory layout are different.)

“Transposing” to d′[t][f], where d′[t] is a vector, is not possible unless your dictionary is non-sparse, i.e. if a given key t is defined for every index f (whereas d′[t, f] is more general). If that’s the case, your solution seems fine, although you could save a bit of time by preallocating the arrays with size length(features) rather than doing push! one element at a time.