REMAINDER
Find the remainder (division) of two numeric arrays, matrices, dataframes, or constants element-wise. When a constant is divided into an array or matrix, each element in the array or matrix will be divided by the constant value. Params: a : OrderedPair|Scalar|Vector The input that will be divided by b. b : OrderedPair|Scalar|Vector The input that will divide a. Returns: out : OrderedPair|Scalar|Vector OrderedPair if a is an OrderedPair.
x: the x-axis of input a.
y: the remainder of input a by input b.
Scalar if a is a Scalar.
c: the remainder of input a by input b.
Vector if a is a Vector.
v: the remainder of input a by input b.
Python Code
import numpy as np
from flojoy import flojoy, OrderedPair, Scalar, Vector
from blocks.MATH.ARITHMETIC.utils.arithmetic_utils import get_val
from functools import reduce
@flojoy
def REMAINDER(
a: OrderedPair | Scalar | Vector, b: list[OrderedPair | Scalar | Vector]
) -> OrderedPair | Scalar | Vector:
"""Find the remainder (division) of two numeric arrays, matrices, dataframes, or constants element-wise.
When a constant is divided into an array or matrix, each element in the array or matrix will be divided by the constant value.
Parameters
----------
a : OrderedPair|Scalar|Vector
The input that will be divided by b.
b : OrderedPair|Scalar|Vector
The input that will divide a.
Returns
-------
OrderedPair|Scalar|Vector
OrderedPair if a is an OrderedPair.
x: the x-axis of input a.
y: the remainder of input a by input b.
Scalar if a is a Scalar.
c: the remainder of input a by input b.
Vector if a is a Vector.
v: the remainder of input a by input b.
"""
initial = get_val(a)
seq = map(lambda dc: get_val(dc), b)
y2 = reduce(lambda u, v: np.remainder(u, v), seq, initial)
match a:
case OrderedPair():
return OrderedPair(x=a.x, y=y2)
case Vector():
return Vector(v=y2)
case Scalar():
return Scalar(c=y2)
Example
Having problems with this example app? Join our Discord community and we will help you out!
This app shows how to use the REMAINDER
and FLOOR_DIVISION
blocks.
Blocks used:
REMAINDER
FLOOR_DIVISION
- 2x
CONSTANT
(set to scalars of 10 and 3) - 2x
BIG_NUMBER
The blocks were connected as shown and the app was run. The result is 3 / 1 = 3 with a remainder of 1.