ValueError: operands could not be broadcast together with different shapes in numpy?
ValueError: operands could not be broadcast together with different shapes in numpy?
我正在尝试使用 k-fold cross validation
,为此我需要相应地执行培训 set.I,如下所示:
num_folds = 5
subset_size = num_training/num_folds
validation_accuracies = []
for i in range(num_folds):
Xcross_valid_set = X_train[i*subset_size:][:subset_size].shape
# print X_train[:i*subset_size].shape,X_train[(i+1)*subset_size:]
Xtrain_set = X_train[:i*subset_size] + X_train[(i+1)*subset_size:]
#Xtrain_set=np.concatenate(X_train[:i*subset_size] , X_train[(i+1)*subset_size:])
Ycross_valid_set=y_train[i*subset_size:][:subset_size]
Ytrain_set=y_train[:i*subset_size]+y_train[(i+1)*subset_size:]
问题是 X_train[:i*subset_size]
的形状是 (0,3072) 而 X_train[(i+1)*subset_size:]
的形状是 (40000,3072) 在 i=0
的情况下。我尝试使用 numpy.concatenate 但没有用。
结果形状将是(40000,3072) 这里第一项给出 0 row.So 如果第一项给出 (10,3072) 第二项给出 (30,3072) 那么结果形状将是 (40,3072) 即 40 行.如何将两种不同的形状合并为一个训练集??
np.concatenate
需要一个数组列表作为第一个参数:
Xtrain_set = np.concatenate([X_train[:i*subset_size], X_train[(i+1)*subset_size:]])
我正在尝试使用 k-fold cross validation
,为此我需要相应地执行培训 set.I,如下所示:
num_folds = 5
subset_size = num_training/num_folds
validation_accuracies = []
for i in range(num_folds):
Xcross_valid_set = X_train[i*subset_size:][:subset_size].shape
# print X_train[:i*subset_size].shape,X_train[(i+1)*subset_size:]
Xtrain_set = X_train[:i*subset_size] + X_train[(i+1)*subset_size:]
#Xtrain_set=np.concatenate(X_train[:i*subset_size] , X_train[(i+1)*subset_size:])
Ycross_valid_set=y_train[i*subset_size:][:subset_size]
Ytrain_set=y_train[:i*subset_size]+y_train[(i+1)*subset_size:]
问题是 X_train[:i*subset_size]
的形状是 (0,3072) 而 X_train[(i+1)*subset_size:]
的形状是 (40000,3072) 在 i=0
的情况下。我尝试使用 numpy.concatenate 但没有用。
结果形状将是(40000,3072) 这里第一项给出 0 row.So 如果第一项给出 (10,3072) 第二项给出 (30,3072) 那么结果形状将是 (40,3072) 即 40 行.如何将两种不同的形状合并为一个训练集??
np.concatenate
需要一个数组列表作为第一个参数:
Xtrain_set = np.concatenate([X_train[:i*subset_size], X_train[(i+1)*subset_size:]])