站长资源脚本专栏

python增加矩阵维度的实例讲解

整理:jimmy2025/3/13浏览2
简介numpy.expand_dims(a, axis) Examples>>> x = np.array([1,2])>>> x.shape(2,)>>> y = np.expand_dims(x, axis=0)>>> yarray([[1, 2]])>>> y.shape(1, 2

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)

以上这篇python增加矩阵维度的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。