S C
S C

Reputation: 294

ValueError using vstack: all the input array dimensions for the concatenation axis must match exactly

I have a matrix epoch in which epoch[i][0] is a m x 5 array, where m varies for each i. For example,

epoch[0][0] = [[-5.50571416e-21, -5.92923063e-21,  4.23516474e-21,
        -2.54109884e-21, -5.08219768e-21],
       [-3.03901510e-06, -1.40172574e-06, -8.46450345e-07,
        -3.90002708e-06, -5.56446205e-07],
       [-7.01145041e-06, -3.47478034e-06,  9.50491200e-08,
        -6.93224460e-06, -3.56839111e-06]]] 
epoch[1][0] = [[-5.50571416e-21, -5.92923063e-21,  4.23516474e-21,
        -2.54109884e-21, 8],
       [-3, -1, -8.46450345e-07,
        -3.90002708e-06, -5.56446205e-07]
       ]]

I want to vertically stack epoch[i][0] for all i. When I try

np.vstack((epoch[0][0],epoch[1][0]))

it works, but when I try a for loop, I get an error. Here's my loop:

X = []
for i in range(19): #there are 19 segments
    X=np.vstack((X,epoch[i][0]))

Here's my error:

ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 0 and the array at index 1 has size 5

Can someone help?

Upvotes: 0

Views: 413

Answers (1)

S C
S C

Reputation: 294

Fixed it by initializing

X = np.zeros((1, 5))

Upvotes: 1

Related Questions