diff options
author | Nico Schlömer <nico.schloemer@gmail.com> | 2023-04-20 18:00:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 18:00:59 +0200 |
commit | 1acac891f99075128450aacf2a4538de3ff9d028 (patch) | |
tree | d7de52ce7cbac0e2ae51eb68ec2ca4289a9eb77f /numpy/core/function_base.py | |
parent | 64e692f741da5bf781870de7f6cd1aa5bb5a4070 (diff) | |
download | numpy-1acac891f99075128450aacf2a4538de3ff9d028.tar.gz |
DEP: deprecate scalar conversions for arrays with ndim > 0 (#10615)
This PR reflects some of the progress achieved in issue #10404 and is used to asses the impact of the changes.
With the changes in this PR, `float(numpy.array([1.0])` now gives a warning; likewise some other things:
```python
import numpy
a = numpy.random.rand(10, 1)
a[0] = numpy.array([1.0]) # okay
a[0] = numpy.array(1.0) # okay
a[0] = 1.0 # okay
b = numpy.random.rand(10)
b[0] = numpy.array([1.0]) # ValueError: setting an array element with a sequence.
b[0, ...] = numpy.array([1.0]) # okay
b[0] = numpy.array(1.0) # okay
b[0] = 1.0 # okay
```
This aligns the behavior of numpy arrays with that of lists:
```python
float([3.14])
```
```
TypeError: float() argument must be a string or a number, not 'list'
```
```python
import numpy as np
a = np.random.rand(5)
a[0] = [3.14]
```
```
ValueError: setting an array element with a sequence.
```
Fixes #10404.
Diffstat (limited to 'numpy/core/function_base.py')
-rw-r--r-- | numpy/core/function_base.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/numpy/core/function_base.py b/numpy/core/function_base.py index c82b495b1..00e4e6b0e 100644 --- a/numpy/core/function_base.py +++ b/numpy/core/function_base.py @@ -168,7 +168,7 @@ def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, y += start if endpoint and num > 1: - y[-1] = stop + y[-1, ...] = stop if axis != 0: y = _nx.moveaxis(y, 0, axis) |