Ju_ska
April 15, 2026, 11:25am
1
Hi,
I have something like:
a = [["a", "1" ,"11"],
["b", "2" ,"22"],
["c", "3" ,"33"]]
3-element Vector{Vector{String}}:
["a", "1", "11"]
["b", "2", "22"]
["c", "3", "33"]
And I would like to get e.g. the “a, b, c” or “1, 2, 3” vectors.
Tried various [:,:][…] combos with success.
Are you looking for something more sophisticated than the following?
julia> map(v -> v[1], a)
3-element Vector{String}:
"a"
"b"
"c"
Ju_ska
April 15, 2026, 11:38am
3
Nope, I wondered if the [:,:] kind of syntax would be usable.
Working fine, thanks.
julia> getindex.(a,1)
3-element Vector{String}:
"a"
"b"
"c"
also works
nilshg
April 15, 2026, 2:27pm
5
And in the specific case for the a, b, c vector
julia> first.(a)
3-element Vector{String}:
"a"
"b"
"c"
(or last for the last “column”, but getindex more generally as mentioned above)
[a...;;][1,:]
[a...;;][2,:]
Dan
June 1, 2026, 10:49pm
7
Another method could be:
julia> using IterTools
julia> nth.(a, 1)
3-element Vector{String}:
"a"
"b"
"c"
Note the broadcasting used with nth (that is nth.(...)).
Also:
stack(a)[1,:]
And:
using TensorCast
@cast b[i] := a[i][1]
What are the drawbacks to defining a specific syntax for this case?
For example like a[:][1]
eldee
June 2, 2026, 10:45am
10
Well, the syntax a[:][1] already exists: it copies a and then selects that copy’s first element.
More generally, a Vector{Vector} is not a Matrix (e.g. it can be ragged), so it’s not the natural concept to use when talking about things like columns.