I have a numpy.ndarray of 3D and I need to calculate its gradient and obtain a new ndarray with the same dimensions. I'm using numpy.gradient to do so but it is returning a list instead. How can I get np.gradient to return a np.ndarray?
force = np.gradient(phi)*(-1)
Where phi is my 300³ matrix and I keep obtaining
print(type(force))
type : <class 'list'>
gradientshould return an array, andprint(type(force))shouldn't produce output in that format. Can you strip your code down to the bare minimum that still contains the buggy part and still demonstrates the bug when you run it, then post that?phiso we can replicate your result. this is weird, because the docstring forgradientsays it should return a list. have you checked whethernp.gradient(phi)-- i.e., sans the*(-1)-- is a list?