【问题标题】:Numpy stack list of ndarrayndarray 的 Numpy 堆栈列表
【发布时间】:2018-07-28 11:44:54
【问题描述】:

我有一个形状为(3, 64, 64) 的图像列表,读取它们并将它们存储在列表images 中。 然后我将堆栈应用于列表:

images = np.stack(images)

我收到了这个错误:

 File "/usr/local/lib/python2.7/dist-packages/numpy/core/shape_base.py", line 350, in stack
raise ValueError('need at least one array to stack')
ValueError: need at least one array to stack'

如果有人对此有任何想法,我将不胜感激。

【问题讨论】:

    标签: python-2.7 list numpy opencv multidimensional-array


    【解决方案1】:

    我可以通过以下方式重现您的错误:

    In [94]: images=[]
    In [95]: np.stack(images)
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-95-adab3e1812bc> in <module>()
    ----> 1 np.stack(images)
    
    /usr/local/lib/python3.5/dist-packages/numpy/core/shape_base.py in stack(arrays, axis, out)
        347     arrays = [asanyarray(arr) for arr in arrays]
        348     if not arrays:
    --> 349         raise ValueError('need at least one array to stack')
        350 
        351     shapes = set(arr.shape for arr in arrays)
    
    ValueError: need at least one array to stack
    

    它会引发错误,因为这是True

    In [97]: not images
    Out[97]: True
    

    【讨论】:

    • 列表不为空(图片不为空,因为我在上面附加了图片)
    • 祝你好运说服stack这不是空的!
    猜你喜欢
    • 1970-01-01
    • 2015-08-07
    • 2019-05-09
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    • 2015-09-16
    • 2021-04-07
    • 2022-01-14
    相关资源
    最近更新 更多