# Np.dot and element wise multiplication

**URL:** <https://community.deeplearning.ai/t/np-dot-and-element-wise-multiplication/180409>\
**Category:** Sequence Models\
**Tags:** coursera-platform\
**Created:** [August 8, 2022, 6:39am UTC](https://community.deeplearning.ai/t/np-dot-and-element-wise-multiplication/180409 "2022-08-08T06:39:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lirone](https://avatars.discourse-cdn.com/v4/letter/l/bcef8e/32.png) [@lirone](https://community.deeplearning.ai/u/lirone)\
**Post date:** [August 8, 2022, 6:39am UTC](https://community.deeplearning.ai/t/np-dot-and-element-wise-multiplication/180409/1 "2022-08-08T06:39:14Z")

</div>

Hi,

It may be a silly question but why for the LSTM cell, we have the element wise multiplication using “\*” for **c\_next** and **a\_next** and the dot product does not work ?  
I did the dot multiplication and it did not work, then I tried using the \* symbol for element wise multiplication.

I’m still confused despite the fact that I thought I knew.

Thank you

---

<div class="post-metadata">

**Author:** ![anon57530071](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@anon57530071](https://community.deeplearning.ai/u/anon57530071)\
**Post date:** [August 8, 2022, 7:18am UTC](https://community.deeplearning.ai/t/np-dot-and-element-wise-multiplication/180409/2 "2022-08-08T07:18:03Z")

</div>

Here is an overview of LSTM cell.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/6/0/603e062a844b3409ade12ed3bf2ac03d3c7279b3.png)

And, I marked three locations in red dotted line.

All are related with calculations of a\_next and c\_next. And, important thing is all are designed to do Hadamard product (wlement-wise product), since it’s a gate function.  
\Gamma\_f, \Gamma\_u, and \Gamma\_o defines which element in a\_prev, c\_prev should be passed to the next step. And, those are output of “sigmoid”, i.e, in the range of 0~1. (It’s like a mask for each element.) So, element-wise operation (Hadamard product) is required for those gate variables.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [August 8, 2022, 4:52pm UTC](https://community.deeplearning.ai/t/np-dot-and-element-wise-multiplication/180409/3 "2022-08-08T16:52:33Z")

</div>

Nobu has done a great job of illuminating the specifics of the LSTM logic. [Here’s a thread](https://community.deeplearning.ai/t/week-2-how-to-decide-to-use-or-np-dot-when-calculating-formula/17467/2) about the general question “When do I use np.dot versus elementwise multiply”. One important “take away” from that thread is you need to carefully observe the notational convention that Prof Ng uses when he writes mathematical formulas: he always uses \* to indicate elementwise multiply.
