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()
Robert Kern <[email protected]> Mon, 5 Oct 2020 16:10:47 -0400
| Newsgroups | gmane.comp.python.scientific.user |
|---|---|
| Message-ID | <CAF6FJiu_i2J+orWq659OkM0KQgj+ds56544wWAw3XqOaRARXkQ@mail.gmail.com> |
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