Skip to content

How to pass *varargs? #1771

Closed
Closed

Description

@henon

How do you pass a variable list of arguments in pythonnet? The problem is the function numpy.gradient(f, *varargs, axis=None, edge_order=1) as documented here: https://numpy.org/doc/stable/reference/generated/numpy.gradient.html

Here is an example in python

>>> import numpy as np
>>> dx=4.0
>>> dy=5.0
>>> zX=[[1,2,3],[4,5,6],[8,9,0]]
>>> np.gradient(zX, dx, dy)
[array([[ 0.75 ,  0.75 ,  0.75 ],
       [ 0.875,  0.875, -0.375],
       [ 1.   ,  1.   , -1.5  ]]), array([[ 0.2,  0.2,  0.2],
       [ 0.2,  0.2,  0.2],
       [ 0.2, -0.8, -1.8]])]
>>>

I tried to pass the variable args with the args tuple but then the python function complains that the number of arguments is incorrect.

Python.Runtime.PythonException: TypeError : invalid number of arguments
 ['  File "C:\\Users\\henon\\AppData\\Local\\python-3.7.3-embed-amd64\\lib\\numpy\\lib\\function_base.py", line 1013, in gradient\n    raise TypeError("invalid number of arguments")\n']   at Python.Runtime.PyObject.Invoke(PyTuple args, PyDict kw)
   at Python.Runtime.PyObject.InvokeMethod(String name, PyTuple args, PyDict kw)

I also tried to pass it as kw["varargs"] but then python says there is no kwarg named "varargs"

So how to call that function?

Activity

  1. locked and limited conversation to collaborators on Apr 25, 2022
  2. converted this issue into a discussion #1772 on Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions