-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support broadcasting #93
Comments
That doesn't seem supported indeed. AFAIK only type stable broadcasts between two similar But since I just proposed the new function newna = NamedArray( fill(tuple(1,1), (5,5)), ( names(a)[1], names(a)[1] ) )
for (n1,v1) in enamerate(a)
for (n2, v2) in enamerate(permutedims(a))
println(n1)
println(n2)
println("val1==$v1")
println("val2==$v2")
newna[n1[1],n2[2]] = (v1,v2)
end
end
#result:
5×5 Named Array{Tuple{Int64,Int64},2}
A ╲ B │ 1 2 3 4 5
──────┼───────────────────────────────────────
1 │ (1, 1) (1, 2) (1, 3) (1, 4) (1, 5)
2 │ (2, 1) (2, 2) (2, 3) (2, 4) (2, 5)
3 │ (3, 1) (3, 2) (3, 3) (3, 4) (3, 5)
4 │ (4, 1) (4, 2) (4, 3) (4, 4) (4, 5)
5 │ (5, 1) (5, 2) (5, 3) (5, 4) (5, 5) |
On a side note, this issue may lead to very unintuitive behaviours depending on the types of the names. E.g. # case with String names
julia> n1 = NamedArray([1,2,3],["1","2","3"])
3-element Named Array{Int64,1}
A │
───┼──
1 │ 1
2 │ 2
3 │ 3
julia> n1 ./ sum(n1,dims=1)
3-element Named Array{Float64,1}
A │
───┼─────────
1 │ 0.166667
2 │ 0.333333
3 │ 0.5
# case with non String names
julia> n2 = NamedArray([1,2,3],[1,2,3])
3-element Named Array{Int64,1}
A │
───┼──
1 │ 1
2 │ 2
3 │ 3
julia> n2 ./ sum(n2,dims=1)
3-element Array{Float64,1}:
0.16666666666666666
0.3333333333333333
0.5
Here we either get an The behaviour appears to be even weirder whenever there are julia> n1 = NamedArray([1,2,3],["1","2","3"])
3-element Named Array{Int64,1}
A │
───┼──
1 │ 1
2 │ 2
3 │ 3
julia> n1 ./ sum(n1,dims=1)
3-element Named Array{Float64,1}
A │
───┼─────────
1 │ 0.166667
2 │ 0.333333
3 │ 0.5
julia> n2 = NamedArray([1,2,3],["1","2",missing])
3-element Named Array{Int64,1}
A │
────────┼──
1 │ 1
2 │ 2
missing │ 3
julia> n2 ./ sum(n2,dims=1)
3-element Array{Float64,1}:
0.16666666666666666
0.3333333333333333
0.5 In both examples, the underlying issue seems to be that E.g. for the second example we have julia> typeof(n1)
NamedArray{Int64,1,Array{Int64,1},Tuple{OrderedCollections.OrderedDict{String,Int64}}}
julia> typeof(sum(n1,dims=1))
NamedArray{Int64,1,Array{Int64,1},Tuple{OrderedCollections.OrderedDict{String,Int64}}}
julia> typeof(n2)
NamedArray{Int64,1,Array{Int64,1},Tuple{OrderedCollections.OrderedDict{Union{Missing, String},Int64}}}
julia> typeof(sum(n2,dims=1))
NamedArray{Int64,1,Array{Int64,1},Tuple{OrderedCollections.OrderedDict{String,Int64}}}
Of course what I really should have done for these examples is to use the julia> n1 ./ sum(n1.array,dims=1)
3-element Named Array{Float64,1}
A │
───┼─────────
1 │ 0.166667
2 │ 0.333333
3 │ 0.5
julia> n2 ./ sum(n2.array,dims=1)
3-element Named Array{Float64,1}
A │
────────┼─────────
1 │ 0.166667
2 │ 0.333333
missing │ 0.5
Perhaps there should be a warning or an error when broadcasting over |
just tested out NamedArrays and it seems to fall short when using broadcasting
the desired result would ideally include both row and column names. As you can see, the whole NamedArray type was forgotten.
The text was updated successfully, but these errors were encountered: