I have a function defined by making use of the first-class nature of Python functions, as follows:
add_relative = np.frompyfunc(lambda a, b: (1 + a) * (1 + b) - 1, 2, 1)
Either I need a way to add a docstring to the function defined as it is, or achieve the same thing using the more common format, so that I can write a docstring in the normal way:
def add_relative(a, b):
"""
Docstring
"""
return np.frompyfunc(lambda a, b: (1 + a) * (1 + b) - 1, 2, 1)(a, b)
which works when the function is called like
add_relative(arr1, arr2)
but I then lose the ability to call methods, for example
add_relative.accumulate(foo_arr, dtype=np.object)
I guess this is because the function becomes more like a class when using frompyfunc
, being derived from ufunc
.
I'm thinking I might need to define a class, rather than a function, but I'm not sure how. I would be ok with that because then I can easily add a docstring as normal.
I tagged this coding-style
because the original method works but simply can't be easily documented, and I'm sorry if the title is not clear, I don't know the correct vocabulary to describe this.