Repository: scipy/scipy

Issue:
BUG: scipy.special.logsumexp raises ValueError for a zero-size array
### Describe your issue.

[`scipy.special.logsumexp`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html) raises a `ValueError` for a zero-size array (see below).

Mathematically, the correct answer for a zero-size array is $\log(\text{empty sum}) = \log(0) = -\infty$.

This error is caused by the [use](https://github.com/scipy/scipy/blob/e2e39f691c048b8ad6dd5e7d4eb5a396a81f8dd3/scipy/special/_logsumexp.py#L105C13-L105C20) of [`np.amax`](https://numpy.org/doc/stable/reference/generated/numpy.amax.html) without specifying `initial=-inf`.

**Solution:** Specify `initial=-np.inf` in the call to `np.amax`. I can submit a PR for this.

### Reproducing Code Example

```python
python3 -c "import scipy; print(scipy.special.logsumexp([]))"
```


### Error message

```shell
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/carlos/venv/lib/python3.12/site-packages/scipy/special/_logsumexp.py", line 100, in logsumexp
    a_max = np.amax(a, axis=axis, keepdims=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/carlos/venv/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 2827, in amax
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/carlos/venv/lib/python3.12/site-packages/numpy/core/fromnumeric.py", line 88, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity
```


### SciPy/NumPy/Python version and system information

```shell
1.11.4 1.26.4 sys.version_info(major=3, minor=12, micro=2, releaselevel='final', serial=0)
Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /opt/arm64-builds/include
    lib directory: /opt/arm64-builds/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= SANDYBRIDGE MAX_THREADS=3
    pc file directory: /opt/arm64-builds/lib/pkgconfig
    version: 0.3.21.dev
  lapack:
    detection method: pkgconfig
    found: true
    include directory: /opt/arm64-builds/include
    lib directory: /opt/arm64-builds/lib
    name: openblas
    openblas configuration: USE_64BITINT= DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= SANDYBRIDGE MAX_THREADS=3
    pc file directory: /opt/arm64-builds/lib/pkgconfig
    version: 0.3.21.dev
  pybind11:
    detection method: config-tool
    include directory: unknown
    name: pybind11
    version: 2.11.0
Compilers:
  c:
    commands: cc
    linker: ld64
    name: clang
    version: 14.0.0
  c++:
    commands: c++
    linker: ld64
    name: clang
    version: 14.0.0
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 0.29.36
  fortran:
    commands: gfortran
    linker: ld64
    name: gcc
    version: 12.1.0
  pythran:
    include directory: ../../pip-build-env-sonu7xbu/overlay/lib/python3.12/site-packages/pythran
    version: 0.14.0
Machine Information:
  build:
    cpu: aarch64
    endian: little
    family: aarch64
    system: darwin
  cross-compiled: true
  host:
    cpu: aarch64
    endian: little
    family: aarch64
    system: darwin
Python Information:
  path: /private/var/folders/76/zy5ktkns50v6gt5g8r0sf6sc0000gn/T/cibw-run-gft7gyfb/cp312-macosx_arm64/build/venv/bin/python
  version: '3.12'
```



Discussion:

Resolving patch:
diff --git a/scipy/special/_logsumexp.py b/scipy/special/_logsumexp.py
--- a/scipy/special/_logsumexp.py
+++ b/scipy/special/_logsumexp.py
@@ -102,7 +102,8 @@ def logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False):
 
     # Scale by real part for complex inputs, because this affects
     # the magnitude of the exponential.
-    a_max = np.amax(a.real, axis=axis, keepdims=True)
+    initial_value = -np.inf if np.size(a) == 0 else None
+    a_max = np.amax(a.real, axis=axis, keepdims=True, initial=initial_value)
 
     if a_max.ndim > 0:
         a_max[~np.isfinite(a_max)] = 0


Test patch:
diff --git a/scipy/special/tests/test_logsumexp.py b/scipy/special/tests/test_logsumexp.py
--- a/scipy/special/tests/test_logsumexp.py
+++ b/scipy/special/tests/test_logsumexp.py
@@ -6,6 +6,11 @@
 
 
 def test_logsumexp():
+    # Test with zero-size array
+    a = []
+    desired = -np.inf
+    assert_equal(logsumexp(a), desired)
+
     # Test whether logsumexp() function correctly handles large inputs.
     a = np.arange(200)
     desired = np.log(np.sum(np.exp(a)))