Re: [Numpy-discussion] deprecating float(x) for ndim > 0
Responding to the post by nico.schloemer@gmail.com (I subscribe to the digest). I just wrote the following code: twb = scipy.optimize.fsolve(phi, tdb, args=(tdb, p, w, hd_tdb, hg_tdb), xtol=1e-8) tdb, p, w, hd_tdb, hg_tdb twb.shape print("wet-bulb temperature {:.5f} [deg K]".format(float(twb))) The output is (313.15, 101325.0, 0.009200033532084696, 40182.343155896095, 2573510.322137241) (1,) wet-bulb temperature 295.17583 [deg K] All arguments are floats, the function phi returns float as well. I did expect the output to be float. Instead I got a 1d array. Were my expectations wrong? The print statement would stop working after deprecation. George
On Wed, 2021-09-15 at 17:25 +0000, george trojan wrote:
Responding to the post by nico.schloemer@gmail.com (I subscribe to the digest).
I just wrote the following code:
twb = scipy.optimize.fsolve(phi, tdb, args=(tdb, p, w, hd_tdb, hg_tdb), xtol=1e-8) tdb, p, w, hd_tdb, hg_tdb twb.shape print("wet-bulb temperature {:.5f} [deg K]".format(float(twb)))
The output is
(313.15, 101325.0, 0.009200033532084696, 40182.343155896095, 2573510.322137241)
(1,)
wet-bulb temperature 295.17583 [deg K]
All arguments are floats, the function phi returns float as well. I did expect the output to be float. Instead I got a 1d array. Were my expectations wrong? The print statement would stop working after deprecation.
Yes, this is exactly the type of issue that we are interested in this discussion. I don't know whether this one could be exactly one of those things that have been fixed in SciPy. But right now the code ends up just "flattening" your 0-D array: x0 = asarray(x0).flatten() Which may be unexpected (or maybe it should be expected?). The question is how common it is. If it is rare enough, I would like to get away with it personally. But if it is too annoying in in the real word... One thing we could try to do is improve the error message (it is pretty good already I think). We could go as far as including instructions depending on whether the array is 1-D or N-D and even link to a website for more pointers. Cheers, Sebastian
George _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
On Thu, 16 Sep 2021, 03:25 george trojan,
I just wrote the following code:
twb = scipy.optimize.fsolve(phi, tdb, args=(tdb, p, w, hd_tdb, hg_tdb), xtol=1e-8) tdb, p, w, hd_tdb, hg_tdb twb.shape print("wet-bulb temperature {:.5f} [deg K]".format(float(twb)))
The output is
(313.15, 101325.0, 0.009200033532084696, 40182.343155896095, 2573510.322137241)
(1,)
wet-bulb temperature 295.17583 [deg K]
All arguments are floats, the function phi returns float as well. I did expect the output to be float. Instead I got a 1d array. Were my expectations wrong?
In the return section for fsolve the documentation states that the return value, `x`, is an `ndarray`.
@george trojan
The SciPy devs are very careful not to break backwards compatibility,
even if the changes are arguably useful. That's why the impact of the
numpy PR remains under the hood for SciPy users.
I'd love to see SciPy become more consistent with array
dimensionality, too, but that's a different issue.
On Wed, Sep 15, 2021 at 11:59 PM Andrew Nelson
On Thu, 16 Sep 2021, 03:25 george trojan,
wrote: I just wrote the following code:
twb = scipy.optimize.fsolve(phi, tdb, args=(tdb, p, w, hd_tdb, hg_tdb), xtol=1e-8) tdb, p, w, hd_tdb, hg_tdb twb.shape print("wet-bulb temperature {:.5f} [deg K]".format(float(twb)))
The output is
(313.15, 101325.0, 0.009200033532084696, 40182.343155896095, 2573510.322137241)
(1,)
wet-bulb temperature 295.17583 [deg K]
All arguments are floats, the function phi returns float as well. I did expect the output to be float. Instead I got a 1d array. Were my expectations wrong?
In the return section for fsolve the documentation states that the return value, `x`, is an `ndarray`.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion
participants (4)
-
Andrew Nelson
-
george trojan
-
Nico Schlömer
-
Sebastian Berg