Integrated python in c# using python.net

31 Views Asked by At
dynamic fResult = scipyStats.f_oneway.InvokeMethod("__call__", args: pyGroupsData);

this excpects multiple arguments as this in python

calculateTotalSum(*arguments) 

how do i pass it in c# note that the * can't be used except with a pointer here's my full code

    using (Py.GIL())
    {
        dynamic np = Py.Import("numpy");
        dynamic scipyStats = Py.Import("scipy.stats");
        dynamic statsmodels = Py.Import("statsmodels.stats.multicomp");

        var groupsData = parameter.GroupedParameterValues.Values;
        var groupLabels = parameter.GroupedParameterValues.Keys;

        var pyGroupsData = new PyList();

        foreach (List<double> groupData in groupsData)
        {
            var pyGroupData = new PyList();
            foreach (double value in groupData)
            {
                pyGroupData.Append(value.ToPython());
            }
            pyGroupsData.Append(pyGroupData);
        }

        //dynamic pyGroupsDataTuple = new PyTuple(pyGroupsData);

        dynamic fResult = scipyStats.f_oneway.InvokeMethod("__call__", args: pyGroupsData);



        double fValue = fResult[0].As<double>();
        double pValueANOVA = fResult[1].As<double>();
        string pValueString = pValueANOVA <= 0.001 ? "<0.001" : pValueANOVA.ToString("0.000");
        

        return new AnovaTestResult
        {
            TestValue = fValue.ToString("0.000"),
            PValue = pValueString,
            //PairwiseComparisons = pairwiseComparisons
        };
    }
}

I'm trying to pass the multiple arguments but the error i get is this Python.Runtime.PythonException: 'at least two inputs are required; got 1.'

0

There are 0 best solutions below