Skip to content

np.gradient can not be called with the current pythonnet API #1804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
henon opened this issue May 30, 2022 · 2 comments
Closed

np.gradient can not be called with the current pythonnet API #1804

henon opened this issue May 30, 2022 · 2 comments

Comments

@henon
Copy link
Contributor

henon commented May 30, 2022

I am reopening an issue which was previously demoted to a question but turns out to be a shortcoming of the pythonnet API. As the discussion #1772 shows, there is no way to successfully call 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]])]
>>>

Various ways to call the function have been tried in #1772 but none work. This should be considered a bug.

@filmor
Copy link
Member

filmor commented May 30, 2022

The methods I gave you in the discussion work fine (the InvokeMethod was just missing the method name), I have added tests for them.

@filmor filmor closed this as completed May 30, 2022
@henon
Copy link
Contributor Author

henon commented May 31, 2022

You are right, it works with the latest version. Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants