Skip to content

np.hstack([ ]) throws IndexError instead of ValueError #8790

@medakk

Description

@medakk

Calling np.hstack([ ]) throws an IndexError. It takes a bit more work to find out the root cause of the error, ie: the empty list.

>>> import numpy as np
>>> np.hstack([ ])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 277, in hstack
    if arrs[0].ndim == 1:
IndexError: list index out of range

np.vstack, on the other hand, throws a more appropriate error.

>>> np.vstack([ ])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 230, in vstack
    return _nx.concatenate([atleast_2d(_m) for _m in tup], 0)
ValueError: need at least one array to concatenate

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions