打印(np.整形(x[0],(1,64,64,3)))我收到整形错误x[0]它是我的第一个图像编号

2024-03-29 14:00:52 发布

您现在位置:Python中文网/ 问答频道 /正文

----> 1 print(np.reshape(x[0],(64,64,3)))
      2 print(y[0])

<__array_function__ internals> in reshape(*args, **kwargs)

~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in reshape(a, newshape, order)
    299            [5, 6]])
    300     """
--> 301     return _wrapfunc(a, 'reshape', newshape, order=order)
    302 
    303 

~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds)
     56     bound = getattr(obj, method, None)
     57     if bound is None:
---> 58         return _wrapit(obj, method, *args, **kwds)
     59 
     60     try:

~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds)
     45     except AttributeError:
     46         wrap = None
---> 47     result = getattr(asarray(obj), method)(*args, **kwds)
     48     if wrap:
     49         if not isinstance(result, mu.ndarray):

ValueError: cannot reshape array of size 1 into shape (64,64,3)

Tags: inpycorenumpyobjlibpackagessite
1条回答
网友
1楼 · 发布于 2024-03-29 14:00:52

目前,我们不知道x[0]的值,也不知道它是如何计算/导出的。从错误消息判断,x[0]的形状似乎为1,在这种情况下,MRE的形状如下所示:

import numpy as np
x = np.zeros(shape=(10, 1))
np.reshape(x[0],(64,64,3))  # produces the error message

如错误消息所示,x[0]的大小与目标形状的大小不匹配。数组的大小是形状项的乘积

具体来说,shape(64, 64, 3)数组需要64*64*3=12288值的大小

但是,x[0]只有一个值,这就是为什么numpy不知道如何执行转换。您需要确保x[0]的大小正确。例如:

import numpy as np

x = np.zeros(shape=(1, 64*64*3))
np.reshape(x[0],(64,64,3)) # this should succeed

相关问题 更多 >