0

What am i doing wrong here?

import numpy as np
import scipy.optimize as so

def f(z):
  return z


guess=np.array([1,1])
z0=so.newton(f,guess)

Im getting the following error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

There is some info on scipy docs about vectorizing the function if its domain is multivalued, but cant quite understand what i have to do.

4
  • Are you sure you want your function to return an array as well (rather than a single value)? Commented Mar 1, 2019 at 15:28
  • Your code snippet works in python3 (giving z0 = array([0., 0.])), but not in python2. Commented Mar 1, 2019 at 15:29
  • Im using Python3.6 on Spyder from university... hmm Commented Mar 1, 2019 at 17:28
  • What version do you use of scipy (I am on 1.2.1) and numpy (1.15.4)? Commented Mar 1, 2019 at 17:44

1 Answer 1

1

If I run your code with an older version of the lib (Python 3.6.3, scipy 1.1.0), then I get the same error that you showed in your question.

When I upgrade to a newer version (same python, scipy 1.2.1) then the error goes away and the code runs fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.