Search code examples
arraysvectorjuliamoduloremainder

Julia modulo of vector (or remainer of vector)


How do I obtain the modulo of a vector in Julia.

There are two ways in Julia to perform a modulo:

mod(9,5)

or equivalently:

9 % 5

However, neither works with a vector.

This also the came for computing the remainder of a vector.


Solution

  • For this you use the element-wise modulus operator .%:

    [34,456,3] .% 2
    

    Which gives:

    3-element Vector{Int64}:
     0
     0
     1
    

    EDIT: equivalently, you can use mod.()