Primary competition visual

Alvin Smart Money Management Classification Challenge

Helping Kenya
$3 000 USD
Challenge completed over 3 years ago
Classification
499 joined
220 active
Starti
Jun 22, 22
Closei
Jul 24, 22
Reveali
Jul 24, 22
how to pad NumPy arrays that don't have the same shape with zeros
Help · 6 Jul 2022, 08:59 · 3

I have a set of NumPy arrays in a list and some of the NumPy arrays don't have the same shape as their other members. I will like to pad them with zeros. Does anyone know how I can achieve this? Thank you

ValueError: could not broadcast input array from the shape (558,10) into shape (558,)

Discussion 3 answers
User avatar
ff
University of Yaoundé I

I suppose you want to fill the 9 next columns of zeros.

X = X.reshape((-1, 1))

padding = np.zeros((558, 9))

X = np.hstack((X, padding))

User avatar
ff
University of Yaoundé I

You're welcome!