np.concatenate和np.hstack

时间:2018-03-15 22:56:28

标签: python numpy

我有以下代码,我想模仿所有标签的串联。

我在使用np.hstack做的是: np.concatenate(前一个标签,新标签)

def createTrainingSVM(path):    
#iterating through the training file and getting all wav files to train SVM
features = []
labels = []
for filename in glob.glob(path):
    #getting the sample rate value: 16000hz and the data read from wav file
    sr_value, x_value = wav.read(filename)
    #calling extract_feat which returns 39 mfcc features for each value in the vector
    vector = extract_feat(x_value, sr_value)#default values

    features.append(vector)
    #create labels for each vector with the particular number being spoken
    labels.append(np.full(len(vector),int(ntpath.basename(filename).split('.')[0])))

final_labels = np.hstack(labels)
final_features = np.vstack(features)
#fitting the model
svmModel.fit(final_features, final_labels)

1 个答案:

答案 0 :(得分:1)

根据numpy.hstack上的文档:

  

这相当于沿第二轴的连接,除了沿第一轴连接的一维数组。