数组a = np.array(1)
很方便,因为它允许a.shape
**
如何在执行返回标量的操作时保留numpy
类类型,例如
b = 0.
c = np.dot(a.T, a)
b+=c
b.shape
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-19-82ed078d10e8> in <module>()
----> 1 b.shape
AttributeError: 'float' object has no attribute 'shape'
**在应该返回标量的复杂操作期间进行维度检查时非常有用(例如,多索引张量求和)