【问题探究】numpy.squeeze()的输入问题

前言:

{

    这篇博客只介绍一个小问题,没有经过多少检索。

}

正文:

{

    numpy.squeeze(a, b)[1]可以把a的shape中b位置的1删除。

#代码1
a = []
a.append([[1,2]])
b = np.squeeze(a, 0)

    我原本以为,代码1执行完后"b=[[1,2]]",但实际"b=[1,2]"。

    代码2则符合预期。

#代码2
a = []
a.append([[1,2]])
b = np.squeeze(np.array(a), 0)

    [1]中也没有明确地介绍此问题,只说输入类型是array_like,但是[2]中说array_like包括list。

}

结语:

{

    总之知道解决办法了,虽然具体原因我也没时间深究。

    参考资料:

    {

        [1]https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.squeeze.html

        [2]https://docs.scipy.org/doc/numpy-1.13.0/glossary.html#term-array-like

    }

}

猜你喜欢

转载自blog.csdn.net/fish_like_apple/article/details/84929181