How to check if a NumPy array is a 1D array
Use .ndim == 1
which contains the number of dimensions in the array.
how-to-check-if-a-numpy-array-is-a-1d-array.py
if a.ndim == 1:
print('a is a 1D array')
else:
print('a is not a 1D array')
You can also use assert
to check that:
example.py
assert a.ndim == 1
which will raise
an AssertionError
if a
is not a one-dimensional array.
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow