[SciPy-User] _minimize_bfgs throws error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Robert Kern robert.kern at gmail.com
Mon Oct 5 16:10:47 EDT 2020


On Mon, Oct 5, 2020 at 3:23 PM Schuldei, Andreas <
andreas.schuldei at th-luebeck.de> wrote:

> thank you for your help. Now i rewrote the packing and unpacking and it
> looks like this:
>
> (just to leave something working for posterity.) Is this as elegant as it
> gets?
>
I would probably rearrange `data` to be (n, 3)-shaped so that the 3-vectors
can remain (3,)-shaped instead of (3,1)-shaped (also, first axis being the
"observation" axis is pretty conventional). Then the packing and unpacking
get a little simpler.

assert data.shape == (n, 3)
center_point = data.mean(axis=0)
guess_a_axis_vector = np.array([1.0, 0.0, 0.0])
guess_b_axis_vector = np.array([0.0, 1.0, 0.0])
guess_phases = np.array([0.0, 0.0])
p0 = np.hstack([center_point, guess_a_axis_vector, guess_b_axis_vector,
guess_phases])

def ellipse_func(x, data):
    center_point = x[0:3]
    a_axis_vector = x[3:6]
    b_axis_vector = x[6:9]
    a_phase, b_phase = x[9:11]
    t = ...
    error = center_point + ... - data
    error_sum = np.sum(error ** 2)
    return error_sum

-- 
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-user/attachments/20201005/b40685a9/attachment.html>


More information about the SciPy-User mailing list