pythonnumpysvmpad

Padding doesn't work when size is 63 and 27


During the iteration, almost all out of 100 arrays get padded apart from two whose sizes are 63 and 27. As a result SVM doesn't work because of size differences of feature arrays.

I tried iterating through once again at the bottom but didn't work. Tried to change the dimensions using a conditional statement, didn't work.

for idx1, f in enumerate(feature):
        if idx1 >= 50: break
        current_feature.append(f[2])
        current_feature.append(f[3])
        current_feature.append(f[4])

    #fixations.append(feature.feature_list)
    current_feature = np.array(current_feature)
    pad_amount = 150 - current_feature.size
    prev = current_feature.size
    np.pad(current_feature, (0, pad_amount), 'constant')
    if current_feature.size != 150:
        np.pad(current_feature, (0, pad_amount), 'constant')
        print(prev)
        print(current_feature.size)
    feed.append(current_feature)

Out of the 100 feature arrays create only two with sizes 67 and 27 will not be padded.

EDIT: Typo while pasting the code.


Solution

  • np.pad don't change the array inplace, it returns new array. Try current_feature = np.pad(current_feature, (0, pad_amount), 'constant')

    (You can remove the first appearance of np.pad(current_feature, (0, pad_amount), 'constant'), for the same reason).