tests = [np.array(2.3), np.array([]), np.array([2.3]), np.array([2.3, 3.6])]
print('{a:30}{s:<10}{l:<10}{sl:<10}'.format(a='repr', s='shape', sl=
    'len(shape)', l='length'))
for a in tests:
    s = a.shape
l = len(a) if a.shape else 0
sl = len(s)
print('{a!r:30}{s:<10}{l:<10}{sl:<10}'.format(a=a, l=l, s=s, sl=sl))
How detect length of a numpy array with only one element?