amrods
September 27, 2021, 8:44am
1
I have several matrices x1, ..., xn
what’s a way to create a named tuple (x1=x1, ..., xn=xn)
without having to type all components one by one?
For example:
x1 = rand(2, 2)
x2 = rand(2, 2)
x3 = rand(2, 2)
lazyhelper(x1, x2, x3)
# returns (x1=x1, x2=x2, x3=x3)
mauro3
September 27, 2021, 9:34am
2
Just:
(; x1, x2, x3)
(needs Julia 1.6)
If you want to automate it for a large number of variables, you’ll either need to define a macro or create an expression and eval
it.
4 Likes
I have a package AddToField.jl that makes the creation of a named tuple easier as well
@addnt begin
@add m1 = ...
@add m2 = f(m1)
end
2 Likes