-
-
Couldn't load subscription status.
- Fork 5.7k
Closed
Description
The behaviour of using map and foreach on arrays of different lengths is inconsistent:
julia> map((x, y) -> typeof(y), [1, 2, 3], [4, 5])
ERROR: DimensionMismatch("dimensions must match")
Stacktrace:
[1] promote_shape at ./indices.jl:154 [inlined]
[2] _promote_shape at ./iterators.jl:317 [inlined]
[3] axes at ./iterators.jl:316 [inlined]
[4] _array_for at ./array.jl:598 [inlined]
[5] collect(::Base.Generator{Base.Iterators.Zip{Tuple{Array{Int64,1},Array{Int64,1}}},getfield(Base, Symbol("##3#4")){getfield(Main, Symbol("##13#14"))}}) at ./array.jl:611
[6] map(::Function, ::Array{Int64,1}, ::Array{Int64,1}) at ./abstractarray.jl:2155
[7] top-level scope at REPL[6]:1
julia> foreach((x, y) -> println(typeof(y)), [1, 2, 3], [4, 5])
Int64
Int64As far as i can tell, foreach takes the smallest length of an array passed to it and iterates over that, whereas map just throws a DimensionMismatch.
Metadata
Metadata
Assignees
Labels
No labels