How to check if a NumPy array is a 1D array

Use .ndim == 1 which contains the number of dimensions in the array.

if a.ndim == 1:
    print('a is a 1D array')
    print('a is not a 1D array')

You can also use assert to check that:

assert a.ndim == 1

which will raise an AssertionError if a is not a one-dimensional array.