Skip to content

sample

add

add(a, b)

A function that adds two numbers.

Parameters:

  • a (float) –

    First number to add.

  • b (float) –

    Second number to add.

Returns:

  • float

    The sum of a and b.

Source code in template/examples/sample.py
def add(a: float, b: float) -> float:
    """
    A function that adds two numbers.

    Parameters
    ----------
    a
        First number to add.
    b
        Second number to add.

    Returns
    -------
    float
        The sum of a and b.
    """
    return a + b

divide

divide(a, b)

A function that divides two numbers, i.e. a/b.

Parameters:

  • a (float) –

    The numerator

  • b (float) –

    The denominator

Returns:

  • float

    The value for a/b

Source code in template/examples/sample.py
def divide(a: float, b: float) -> float:
    """
    A function that divides two numbers, i.e. a/b.

    Parameters
    ----------
    a
        The numerator
    b
        The denominator

    Returns
    -------
    float
        The value for a/b
    """
    if b == 0:
        raise ValueError("Uh oh! The value for b should not be 0.")

    return a / b

make_array

make_array(val, length=3)

A function to transform a number into a numpy array.

Parameters:

  • val (float) –

    Number to turn into an array.

  • length (int, default: 3 ) –

    The length of the array.

Returns:

  • NDArray

    An array composed of val.

Source code in template/examples/sample.py
def make_array(val: float, length: int = 3) -> NDArray:
    """
    A function to transform a number into a numpy array.

    Parameters
    ----------
    val
        Number to turn into an array.
    length
        The length of the array.

    Returns
    -------
    NDArray
        An array composed of `val`.
    """
    return np.array([val] * length)