Make ipywidget.interact take ndarray arguments
10:02 10 Nov 2025

I couldn't find exactly my scenario in other questions, please redirect me if you see fit but:

I have a function with args with variable length, which i check inside and take different actions based on it. In the end however, i should have 10 values, an ndarray of 5 for qs and same for dqs, and i need them like this separately, because i send them to a physical equipment.

def function(self, *args, val: float):

    if len(args) == 1 and isinstance(args[0], np.ndarray) and len(args[0]) == 5:
        qs = args[0]
        dqs = [1]*5
    elif len(args) == 2 and all(isinstance(lst, np.ndarray) and len(lst) == 5 for lst in args):
        ...
    elif len(args) == 5:
        ...
    elif len(args) == 10:
        ...
    else:
        raise ValueError

How can i then call interact on it, basically with 10 sliders for args and 1 for val? i keep ending up on the ValueError branch.

This doesn't work, just put it down as an example, which in my head would make sense.

interact(function, args= np.array([0,0,0,0,0]), val=(0,100))

Thank you, any idea is appreciated

python interactive ipywidgets