Re: _minimize_bfgs throws error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Edward Montague <[email protected]> Wed, 7 Oct 2020 06:04:15 +1300
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CAN5Oy2gFXZ8=VEMJmPkuJz5OVX-8oxBWfcLDS=nU-=O+ez63DA@mail.gmail.com> |
Apologies. Having some difficulty with login, insecure login blocked. On Tue, Oct 6, 2020 at 9:12 AM Robert Kern <[email protected]> wrote: > On Mon, Oct 5, 2020 at 3:23 PM Schuldei, Andreas < > [email protected]> 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 > _______________________________________________ > SciPy-User mailing list > [email protected] > https://mail.python.org/mailman/listinfo/scipy-user > _______________________________________________ SciPy-User mailing list [email protected] https://mail.python.org/mailman/listinfo/scipy-user