With x = Any[[1,2],[2,3],[3,4],[4,5]]
, I tried the following line with Julia0.4.0
x[ x .== [3,4] ]
but it resulted in an error
ERROR: DimensionMismatch("arrays could not be broadcast to a common size")
I expected it to give something like Any[ [3,4] ]
because
x[3] == [3,4] # => true
is no problem. Although this operation itself may not be useful, I would like to know what the error message means. So I would appreciate any hints why this error occurs.
To make an element-by-element comparison, Julia requires that both arrays have the same number of elements. This can be achieved in this case with a comprehension:
So the question in my mind was "why doesn't Julia broadcast the
[3,4]
into this shape automatically?". The following example is broadcast correctly:It appears that Julia's broadcast mechanism is unable to infer that we want
[3,4]
to be broadcast into[[3,4],[3,4],[3,4],[3,4]]
rather than some other shape of array.