C5 [Week 1] Problem slicing Tensor in "Jazz Solo with an LSTM Network"

I cannot seem to figure out the correct way to slice the Input tensor X in the djmodel function. I have tries 2 options,

        # Step 2.A: select the "t"th time step vector from X. 
        x = Lambda(lambda x: X[:,t,:])(X)
        #x = X[:,t,:]  # also tried to simply slice it

        # Step 2.B: Use reshaper to reshape x to be (1, n_values) (≈1 line)
        x = reshaper(x)

But I get this error:

The layer “reshape” has multiple inbound nodes, with different output shapes. Hence the notion of “output shape” is ill-defined for the layer. Use get_output_shape_at(node_index) instead.

The size of the slice is x.shape = (None, 90), but the description says that the size should be (n_values,) = (90,), is that the issue?


There’s a much easier way to select a sclice of X

Can you please give me more details, I’m struck here for the past hour :frowning: … I tried doing X[:,t,:] too

I used x=X[:,t,:] and works for me

1 Like

Restarting the kernel fixed it… :expressionless: Something must’ve been messed up before…


I had the same issue, and restarting the kernel fixed it for me, as well! Thanks for posting this or I would have been chasing my tail for hours.


I just had the same issue as Roland and Marcus. Thanks all for posting.

1 Like

Based on the guidance, I tried using tf.slice but couldn’t get it to work properly.

Dimensions of tf.slice(X,[0,t,0],[-1,t,-1]) become [0, 90] and leads to the following:

ValueError: total size of new array must be unchanged, input_shape = [0, 90], output_shape = [1, 90]

Am I using this wrong, or does it not really apply in the first place?



X[:,t,:] seemed like the obvious choice and was the first thing I tried too and i went around for hours, including restarting the kernel with other methods before reading this thread, restarting, and retrying this method.

Does anybody have any ideas for why the kernel seems to have trouble here? Is there some kind of caching going on with the global variables that make it keep some bad state from failed attempts?