将3d阵列广播到4d阵列时出现问题

时间:2019-04-11 03:12:35

标签: python-3.x numpy-ndarray numpy-broadcasting

广播3d到4d阵列的问题

def create_croppings(self,numpy_array):         #抖动颜色通道         numpy_array = self.colour_channel_jitter(numpy_array)

    y_dim, x_dim = numpy_array.shape[:2]
    # Have the x & y coordinate of the crop
    crop_x = random.randrange(x_dim - self.cropSize)
    crop_y = random.randrange(y_dim - self.cropSize)
    # Select which image ordering we'll use from the maximum hamming set
    perm_index = random.randrange(self.numPermutations)
    final_crops = np.zeros(
        (self.tileSize, self.tileSize, 3, 9), dtype=np.float32)
    for row in range(3):
        for col in range(3):
            x_start = crop_x + col * self.cellSize + \
                random.randrange(self.cellSize - self.tileSize)
            y_start = crop_y + row * self.cellSize + \
                random.randrange(self.cellSize - self.tileSize)
            # Put the crop in the list of pieces randomly according to the
            # number picked
            final_crops[:, :, :, self.maxHammingSet[perm_index, row * 3 + col]
                        ] = numpy_array[y_start:y_start + self.tileSize, x_start:x_start + self.tileSize, :,np.newaxis]
    return final_crops, perm_index

“在这里,我试图在我的代码final_crops(4d array)的最后一行中将3d数组的值保存到4d数组。但是它引发以下错误请帮助我” “错误” create_croppings     ] = numpy_array [y_start:y_start + self.tileSize,x_start:x_start + self.tileSize,:]

ValueError:形状不匹配:形状(64,64,3)的值数组无法广播到形状(3,64,64,3)的索引结果

def create_croppings(self,numpy_array):         #抖动颜色通道         numpy_array = self.colour_channel_jitter(numpy_array)

    y_dim, x_dim = numpy_array.shape[:2]
    # Have the x & y coordinate of the crop
    crop_x = random.randrange(x_dim - self.cropSize)
    crop_y = random.randrange(y_dim - self.cropSize)
    # Select which image ordering we'll use from the maximum hamming set
    perm_index = random.randrange(self.numPermutations)
    final_crops = np.zeros(
        (self.tileSize, self.tileSize, 3, 9), dtype=np.float32)
    for row in range(3):
        for col in range(3):
            x_start = crop_x + col * self.cellSize + \
                random.randrange(self.cellSize - self.tileSize)
            y_start = crop_y + row * self.cellSize + \
                random.randrange(self.cellSize - self.tileSize)
            # Put the crop in the list of pieces randomly according to the
            # number picked
            final_crops[:, :, :, self.maxHammingSet[perm_index, row * 3 + col]
                        ] = numpy_array[y_start:y_start + self.tileSize, x_start:x_start + self.tileSize, :]
    return final_crops, perm_index

我收到以下错误   x [image_num])   在create_croppings中的第105行,文件“ /home/raghuram/Desktop/Semisupervised_Image_Classifier-master/image_preprocessing/image_transform.py”     ] = numpy_array [y_start:y_start + self.tileSize,x_start:x_start + self.tileSize ,:] ValueError:形状不匹配:形状(64,64,3)的值数组无法广播到形状(3,64,64,3)的索引结果

0 个答案:

没有答案