How to CartesianIndex array comprehension?

(CartesianIndex(1,1),) .+ [CartesianIndex(i,i) for i in 1:10]

Wrapping it in a tuple indicates the first argument is to be broadcast. This is arguably a case where defensive programming gets in the way. If we were confident that no one would try to broadcast over the “elements” of a CartesianIndex we could make what you tried work.

3 Likes