0

I have a numpy array v with shape (1000, 68), v is supposed to padding to 100 dimension with 0s. As a result, the v's shape will be (1000, 100)

I tried to use the following approaches:

t = np.lib.pad(v, (16, 16), 'minimum') # numpy method

t = sequence.pad_sequences(v, maxlen = 100, padding = 'post') # Keras text processing method

Above two methods returned the t with correct shape (1000, 100), but each array t[n] (n from 0 to 99) is a zero vector [0, 0, 0, ....0]

1 Answer 1

1

Following numpy.pad documentation, I tried

np.pad(v, [(0,0), (16,16)], 'constant')

with the expected result: 16 columns of zeros added on the left, and 16 on the right.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to use a for loop to pad each array literately, and it worked. But your method is faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.