# D5W1 A1 Assignment Exercise 7 LSTM Backward Pass need help

**URL:** <https://community.deeplearning.ai/t/d5w1-a1-assignment-exercise-7-lstm-backward-pass-need-help/154874>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [July 5, 2022, 1:14am UTC](https://community.deeplearning.ai/t/d5w1-a1-assignment-exercise-7-lstm-backward-pass-need-help/154874 "2022-07-05T01:14:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson\_Tam](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nelson_tam/32/19929_2.png) [@Nelson\_Tam](https://community.deeplearning.ai/u/Nelson_Tam)\
**Post date:** [July 5, 2022, 1:14am UTC](https://community.deeplearning.ai/t/d5w1-a1-assignment-exercise-7-lstm-backward-pass-need-help/154874/1 "2022-07-05T01:14:51Z")

</div>

I am trying to implement D5W1 A1 Assignment Exercise 7 " LSTM Backward Pass" but got stuck in understanding this part in parameter derivates

#### Parameter Derivatives

𝑑𝑊𝑓=𝑑𝛾⟨𝑡⟩𝑓[𝑎𝑝𝑟𝑒𝑣𝑥𝑡]𝑇(11)(11)dWf=dγf⟨t⟩[aprevxt]T𝑑𝑊𝑢=𝑑𝛾⟨𝑡⟩𝑢[𝑎𝑝𝑟𝑒𝑣𝑥𝑡]𝑇(12)(12)dWu=dγu⟨t⟩[aprevxt]T𝑑𝑊𝑐=𝑑𝑝𝑐˜⟨𝑡⟩[𝑎𝑝𝑟𝑒𝑣𝑥𝑡]𝑇(13)(13)dWc=dpc~⟨t⟩[aprevxt]T𝑑𝑊𝑜=𝑑𝛾⟨𝑡⟩𝑜[𝑎𝑝𝑟𝑒𝑣𝑥𝑡]𝑇(14)

The instruction here appear to ask us to concatenate the matrix a\_prev with xt. but they are of different size and once I done that the following numpy error appears.

* * *

TypeError Traceback (most recent call last)  
 in   
19 da\_next\_tmp = np.random.randn(5,10)  
20 dc\_next\_tmp = np.random.randn(5,10)  
—\> 21 gradients\_tmp = lstm\_cell\_backward(da\_next\_tmp, dc\_next\_tmp, cache\_tmp)  
22 print(“gradients["dxt"][1][2] =”, gradients\_tmp[“dxt”][1][2])  
23 print(“gradients["dxt"].shape =”, gradients\_tmp[“dxt”].shape)

in lstm\_cell\_backward(da\_next, dc\_next, cache)  
46 print (a\_prev.shape)  
47 print (xt.shape)  
—\> 48 concat = np.concatenate(a\_prev, xt)  
49 print (concat.shape)  
50 dWf = np.dot(dft, (np.concatenate(a\_prev, xt)).T)

\< **array\_function** internals\> in concatenate(\*args, \*\*kwargs)

TypeError: only integer scalar arrays can be converted to a scalar index

For debugging purpose the shape of a\_prev and xt are:

(5, 10)  
(3, 10)

My lab ID is pahlbtkn

---

<div class="post-metadata">

**Author:** ![Community-Team](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/community-team/32/136466_2.png) [@Community-Team](https://community.deeplearning.ai/u/Community-Team)\
**Post date:** [July 6, 2022, 1:13pm UTC](https://community.deeplearning.ai/t/d5w1-a1-assignment-exercise-7-lstm-backward-pass-need-help/154874/3 "2022-07-06T13:13:48Z")

</div>

Made this topic public on July 6, 2022, 1:13pm UTC


