def mat31_mod(b, m):
    """Compute moduli of a 3x1 matrix.

    Parameters
    ----------
    b : 'list' ['float']
        3x1 matrix.
    m : 'float'
        modulus.

    Returns
    -------
    res : 'list' ['float']
        3x1 matrix.
    """
    res = [0, 0, 0]
    for i in range(3):
        res[i] = int(b[i] - int(b[i] / m) * m)
        # if negative, add back modulus m
        if res[i] < 0:
            res[i] += m
    return res