assert(a.shape == ())

a = np.array([[1]])
print(a)
a = np.squeeze(a) # To make sure your cost's shape is what we expect (e.g. this turns [[17]] into 17).
print('a:',a)
print(a.shape)
assert(a.shape == ())
b = np.array(1)
print('b:',b)
print(b.shape)

assert(b.shape == ())

看样子应该np.squeeze转化为数,类型仍旧是ndarray,

如果b = 1

print(b.shape),则会出错

AttributeError: 'int' object has no attribute 'shape'

你可能感兴趣的:(assert(a.shape == ()))