python增加矩阵维度

转自:https://blog.csdn.net/u013381011/article/details/78341563

  • numpy.expand_dims(a, axis) 
    Examples
>>> x = np.array([1,2])
>>> x.shape
(2,)
>>> y = np.expand_dims(x, axis=0)
>>> y
array([[1, 2]])
>>> y.shape
(1, 2)
>>> y = np.expand_dims(x, axis=1)  # Equivalent to x[:,newaxis]
>>> y
array([[1],
       [2]])
>>> y.shape
(2, 1)

猜你喜欢

转载自blog.csdn.net/orangefly0214/article/details/80934028