How to insert a constant element at a list of indices of a Vector of Vectors/Matrices

QuatRotation is not a scalar with respect to broadcasting. Using

Q[ids] .= Ref(UnitQuaternion(0, 0, 1, 0))

works, because Refs are treated as scalars.

Note however that this is dangerous when the right hand side is mutable / has mutable fields, i.e. a Vector{...}, because that will assign the same object to every index on the left. Not a problem here, but it’s a trap I’ve fallen in more times than I like to admit :slight_smile: Same goes for fill([1,2,3], 5) for example.

2 Likes