assert(cost.shape == ())
shape
assert cost.shape == ()
assert(cost.shape == (), 'shape should be scalar')
() 是一个空元组,这个断言检查 cost 的形状是否为空元组。因此它检查 cost 是否是一个标量。
()
cost
np.array(3.14159).shape == ()
shape
属性的结果是一个空元组。 - Ignacio Vazquez-Abramsassert cost.shape == ()
- Antti Haapala -- Слава Україніassert(cost.shape == (), 'shape should be scalar')
,它将总是为真。 - Nick T