On 4/20/23, Sebastian Berg <sebast...@sipsolutions.net> wrote: > Hi all, > > Unlike conversions of 0-d arrays via: > > float(np.array([1])) > > conversions of 1-D or higher dimensional arrays with a single element > are a bit strange: > > float(np.array([1])) > > And deprecating it has come up often enough with many in favor, but > also many worried about the possible annoyance to users. > I decided to give the PR a shot, I may have misread the room on it > though: > > https://github.com/numpy/numpy/pull/10615 > > So if this turns out noisy (or you may simply disagree), I am happy to > revert! > > There was always the worry that it might be painful for downstream. > SciPy, pandas, matplotlib should all be fine (were fixed in the past > years). And the fact that SciPy required much more changes than the > other gives me some hope that many libraries won't mind. > > For end-users, I would lean towards taking it slow, but if you see > issues there we can also revert of course. > > Cheers, > > Sebastian > >
Thanks Nico, and Sebastian, and everyone else involved in the PRs. This also affects `np.float64`: ``` In [61]: np.__version__ Out[61]: '1.25.0.dev0+1203.g1acac891f' In [62]: np.float64(0.0) Out[62]: 0.0 In [63]: np.float64(np.array(0.0)) Out[63]: 0.0 In [64]: np.float64(np.array([0.0])) <ipython-input-64-0f0309f2cf0c>:1: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.) np.float64(np.array([0.0])) Out[64]: 0.0 In [65]: np.float64(np.array([0.0, 0.0])) Out[65]: array([0., 0.]) ``` In 1.24.2, `np.float64(np.array([0.0])` returns the the scalar 0.0. If passing arrays to `np.float64()` is intentionally supported, it seems it would be more consistent for `np.float64(np.array([0.0]))` to return `np.array([0.0])`. That is how the other numpy types work (e.g. `np.complex128`, `np.int64`, etc.). But I'm not sure if there is a deprecation/update path that would get us there. Warren > > _______________________________________________ > NumPy-Discussion mailing list -- numpy-discussion@python.org > To unsubscribe send an email to numpy-discussion-le...@python.org > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ > Member address: warren.weckes...@gmail.com > _______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com