'convert dictionary to abstract matrix in julia

I'm trying to do dimension reduction, and I got a:

d = Dict{Tuple{String, String}, Vector{Float64}}

Trying to apply umap on it.

While umap can only accepts abstractmatrix, so I do collect(d), but the dict is converted into vector, not array.

How do I convert it correctly to successfully apply umap?



Solution 1:[1]

You should be able to use

hcat(values(d)...)

using values you get a vector of vectors, the dictionary values. And hcat will concatenate them horizontally, however this function takes each vector as a different argument and therefore you need to splat this array into its elements, that is what the three dots ... do.

Check the documentation for splatting

As noted in the comments, a more efficient alternative is

reduce(hcat, values(d))

which achieves the same avoiding splatting.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1