To Andrew Nelson:
> In the return section for fsolve the documentation states that the return
> value, `x`, is an `ndarray`.
True, my bad. There is another issue with `fsolve`: it implicitly changes
the argument passed to `func`. Consider
def func(x):
# x = float(x)
if not np.isscalar(x) and x.shape != ():
raise ValueError('The argument must be a number or a 0-d array')
return x - 1
fsolve(func, np.array(2.0))
---------------------------------------------------------------------------ValueError
Traceback (most recent call
last)/tmp/ipykernel_1017360/2091764495.py in <module> 5
return x - 1 6 ----> 7 fsolve(func, np.array(2.0))
. . .
ValueError: The argument must be a number or a 0-d array
I had the commented out line in my code (in real life I am calling a
library function that accepts only
numeric types, not arrays). Changing this to line to x = x.item() makes sense.
The documentation states that `func` takes at least one (possibly
vector) argument. It must take a vector.
_______________________________________________
NumPy-Discussion mailing list
[email protected]
https://mail.python.org/mailman/listinfo/numpy-discussion