NumPy: Prüfen ob ein Array ein 1D-Array ist
Verwende .ndim == 1, was die Anzahl der Dimensionen im Array enthält.
how-to-check-if-a-numpy-array-is-a-1d-array.py
if a.ndim == 1:
print('a ist ein 1D-Array')
else:
print('a ist kein 1D-Array')Du kannst auch assert verwenden, um das zu prüfen:
assert_1d_array.py
assert a.ndim == 1was eine AssertionError auslöst, wenn a kein eindimensionales Array ist.
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