Skip to content

SPLIT_VECTOR

The SPLIT_VECTOR node returns a vector that is splited by a given indexInputs ------ default : Vector The input vectorParams:index : intindex which you want to split your vector byReturns:out : VectorSplited input vector
Python Code
from numpy.random import permutation
from flojoy import flojoy, Vector
from typing import TypedDict
from sklearn.model_selection import train_test_split


class resultSplit(TypedDict):
    vector1: Vector
    vector2: Vector


@flojoy
def SPLIT_VECTOR(
    default: Vector,
    index: int = 0,
) -> resultSplit:
    """The SPLIT_VECTOR node returns a vector that is splited by a given index

    Inputs
    ------
    default : Vector
        The input vector

    Parameters
    ----------
    index : int
        index which you want to split your vector by

    Returns
    -------
    Vector
        Splited input vector
    """
    if index > len(default.v) - 1:
        raise ValueError(f"Given index is larger than the input vector, index: {index}")

    return resultSplit(
        vector1=Vector(default.v[:index]), vector2=Vector(default.v[index:])
    )

Find this Flojoy Block on GitHub

Example

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

In this example, we generate a vector type data using LINSPACE node.

Using SPLIT_VECTOR, split the vector type into two different vectors by its index and visualize using SCATTER node.