如何重塑numpy数组?我无法将大小为87880的数组重塑为形状(130,20,26,1)错误

时间:2020-09-03 02:24:03

标签: python numpy numpy-ndarray

我的代码如下:

    idxs = [np.where(np.argmax(y_test, axis=1) == i)[0][0]
        for i in range(nb_classes)]
if targeted:
    if viz_enabled:
  # Initialize our array for grid visualization
        

        adv_inputs = np.array(
                    [[instance] * nb_classes for instance in x_test[idxs]],
                    dtype=np.float32)
    else:
        adv_inputs = np.array(
                        [[instance] * nb_classes for
                        instance in x_test[:source_samples]], dtype=np.float32)

    one_hot = np.zeros((nb_classes, nb_classes))
    one_hot[np.arange(nb_classes), np.arange(nb_classes)] = 1

    adv_inputs = adv_inputs.reshape(
        (source_samples * nb_classes, img_rows, img_cols, nchannels))
    adv_ys = np.array([one_hot] * source_samples,
                  dtype=np.float32).reshape((source_samples *
                                             nb_classes, nb_classes

我想重塑adv_inputs。 x_test形状为(5982,20,26,1),y_test形状为(5982,13)

0 个答案:

没有答案