In addition to the other answers, you can also use slicing with numpy.newaxis
:
>>> from numpy import zeros, newaxis
>>> a = zeros((6, 8))
>>> a.shape
(6, 8)
>>> b = a[:, :, newaxis]
>>> b.shape
(6, 8, 1)
Or even this (which will work with an arbitrary number of dimensions):
>>> b = a[..., newaxis]
>>> b.shape
(6, 8, 1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…