Skip to content

ORDERED_PAIR_DELETE

Returns an OrderedPair with elements deleted from requested indices. Deletes from both x and y axes. Params: default : OrderedPair The input OrderedPair to delete from indices : Array specified indices to delete value(s) at from the input OrderedPair length : int number of elements to delete from the input OrderedPair, default is 1 (this only applies when one index is specified for indices parameter) Returns: out : OrderedPair The new OrderedPair with element(s) deleted from the input OrderedPair
Python Code
from numpy import any, array, delete, arange
from flojoy import flojoy, OrderedPair, Array


@flojoy
def ORDERED_PAIR_DELETE(
    default: OrderedPair,
    indices: Array,
    length: int = 1,
) -> OrderedPair:
    """Returns an OrderedPair with elements deleted from requested indices.

    Deletes from both x and y axes.

    Parameters
    ----------
    default : OrderedPair
        The input OrderedPair to delete from
    indices: Array
        specified indices to delete value(s) at from the input OrderedPair
    length: int
        number of elements to delete from the input OrderedPair, default is 1 (this only applies when one index is specified for indices parameter)

    Returns
    -------
    OrderedPair
        The new OrderedPair with element(s) deleted from the input OrderedPair
    """

    # unwrap the indices first
    indices = array(indices.unwrap(), dtype=int)

    assert (
        len(default.x) > len(indices)
    ), "The length of indices parameter must be less than the length of the OrderedPair."
    assert any(indices >= 0), "The indices must be greater than zero."

    if len(indices) == 1:
        assert (
            (indices[0] + (length - 1)) < len(default.x)
        ), "The length of items to delete starting from index parameter must not exceed the length of the OrderedPair."

    if len(indices) > 1:
        x = delete(default.x, indices, None)
    else:
        indices = arange(indices[0], length)
        x = delete(default.x, indices, None)

    if len(indices) > 1:
        y = delete(default.y, indices, None)
    else:
        indices = arange(indices[0], length)
        y = delete(default.y, indices, None)

    return OrderedPair(x=x, y=y)

Find this Flojoy Block on GitHub

Example

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

This app uses ordered pair transformation techniques.

First the necessary blocks were added:

  • LINSPACE
  • SINE
  • ORDERED_PAIR_LENGTH
  • ORDERED_PAIR_INDEXING
  • ORDERED_PAIR_DELETE
  • 2x BIG_NUMBER
  • TABLE

LINSPACE and SINE created an ordered pair data type (x and y axis pairs). ORDERED_PAIR_LENGTH extracts the length of an ordered pair (this length is viewed with BIG_NUMBER here). ORDERED_PAIR_INDEXING extracts a single value from either the x or y axes (this value is viewed with BIG_NUMBER here). ORDERED_PAIR_DELETE deletes single indexes from both the x or y axes and outputs a new ordered pair (the new ordered pair is viewed with BIG_NUMBER here).

The blocks were connected as shown and the app was run.