Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 将数据重塑为图像值错误:无法将输入数组从形状(13072)广播到形状(32,3)_Python 2.7_Image Processing_Multidimensional Array_2d - Fatal编程技术网

Python 2.7 将数据重塑为图像值错误:无法将输入数组从形状(13072)广播到形状(32,3)

Python 2.7 将数据重塑为图像值错误:无法将输入数组从形状(13072)广播到形状(32,3),python-2.7,image-processing,multidimensional-array,2d,Python 2.7,Image Processing,Multidimensional Array,2d,我正试图将数据重塑为图像,如下所示。除了最后一行代码外,所有操作都很正常: y[i]=image2 我想将结果存储在新变量y中。我在代码y[I]=image2行中得到此错误: **ValueError: could not broadcast input array from shape (1,3072) into shape (32,3)** 我的代码: from numpy import * import cPickle import scipy.io as io

我正试图将数据重塑为图像,如下所示。除了最后一行代码外,所有操作都很正常:

y[i]=image2
我想将结果存储在新变量
y
中。我在代码
y[I]=image2
行中得到此错误:

**ValueError: could not broadcast input array from shape (1,3072) into shape (32,3)**
我的代码:

    from numpy import *
    import cPickle
    import scipy.io as io
    from random import randrange

      y = [len(v) for v in batch_1.values()]

   Y = zeros([len(batch_1['data'][:]),3072])
   for i in range(len(batch_1['data'][:])):  #len() =10000  
        image = batch_1['data'][i]
        image.shape = (3, 32, 32)
        image_result = copy(image.transpose((1, 2, 0)))
        image_result = reshape(image_result, (1, 3072))
        Y[i] = image_result

问题在于额外的维度。将
(13072)
替换为
3072

编辑

您的代码也存在更多问题。没有定义
Y
,我想你的意思是:

image2 = reshape(image_result, (1, 3072))
新代码应如下所示(未测试):


问题在于额外的维度。将
(13072)
替换为
3072

编辑

您的代码也存在更多问题。没有定义
Y
,我想你的意思是:

image2 = reshape(image_result, (1, 3072))
新代码应如下所示(未测试):


我在未定义中得到了这个变量y,我能像这样初始化y[i]=0(13072)吗?我想这行:
image\u result=restrape(image2,(13072))
你的意思是
image2=restrape(image\u result,(13072))
@ahmedmazari检查我的新answer@ahmedmazari您知道我们无法运行代码,因为我们没有批处理1!我在未定义中得到了这个变量y,我能像这样初始化y[i]=0(13072)吗?我想这行:
image\u result=restrape(image2,(13072))
你的意思是
image2=restrape(image\u result,(13072))
@ahmedmazari检查我的新answer@ahmedmazari您知道我们无法运行代码,因为我们没有批处理1!