Skip to content

FLOOR_DIVIDE

Download Flojoy Studio to try this app
Floor divide two or more numeric arrays, matrices, dataframes, or constants element-wise. AKA interger division. 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 result of the floor division of input a by input b. Scalar if a is a Scalar. c: the result of the floor division of input a by input b. Vector if a is a Vector. v: the result of the floor division 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 FLOOR_DIVIDE(
    a: OrderedPair | Scalar | Vector, b: list[OrderedPair | Scalar | Vector]
) -> OrderedPair | Scalar | Vector:
    """Floor divide two or more numeric arrays, matrices, dataframes, or constants element-wise.

    AKA interger division.

    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 result of the floor division of input a by input b.

        Scalar if a is a Scalar.
        c: the result of the floor division of input a by input b.

        Vector if a is a Vector.
        v: the result of the floor division of input a by input b.
    """

    initial = get_val(a)

    seq = map(lambda dc: get_val(dc), b)
    y1 = reduce(lambda u, v: np.floor_divide(u, v), seq, initial)

    match a:
        case OrderedPair():
            return OrderedPair(x=a.x, y=y1)
        case Vector():
            return Vector(v=y1)
        case Scalar():
            return Scalar(c=y1)

Find this Flojoy Block on GitHub

Example App

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

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.