# Week 2 assignment - Error

**URL:** <https://community.deeplearning.ai/t/week-2-assignment-error/490162>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [November 9, 2023, 12:43pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162 "2023-11-09T12:43:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![saminu](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@saminu](https://community.deeplearning.ai/u/saminu)\
**Post date:** [November 9, 2023, 12:43pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/1 "2023-11-09T12:43:30Z")

</div>

Hello,  
I am working on my week two assignment of neural network and got stuck in the last stage. I have implemented the codes for the model but it keeps throwing the error: ValueError: shapes (1,4) and (2,3) not aligned: 4 (dim 1) != 2 (dim 0)

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [November 9, 2023, 1:28pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/2 "2023-11-09T13:28:48Z")

</div>

Please share your full error.

---

<div class="post-metadata">

**Author:** ![saminu](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@saminu](https://community.deeplearning.ai/u/saminu)\
**Post date:** [November 9, 2023, 1:49pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/3 "2023-11-09T13:49:57Z")

</div>

Can I include the code?

---

<div class="post-metadata">

**Author:** ![saminu](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@saminu](https://community.deeplearning.ai/u/saminu)\
**Post date:** [November 9, 2023, 1:54pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/4 "2023-11-09T13:54:23Z")

</div>

I wanted to complete the logistic regression model to compute Y\_predict\_test and Y\_predict\_train. I wrote the code but seems like the matrix multiplication is an issue.

---

<div class="post-metadata">

**Author:** ![saifkhanengr](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/saifkhanengr/32/152858_2.png) [@saifkhanengr](https://community.deeplearning.ai/u/saifkhanengr)\
**Post date:** [November 9, 2023, 3:45pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/5 "2023-11-09T15:45:18Z")

</div>

You cannot include the code. Only share your full error.

---

<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:** [November 9, 2023, 3:53pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/6 "2023-11-09T15:53:11Z")

</div>

It looks like your X matrix is the wrong shape: it doesn’t match the shape of the w vector. So you must have passed the wrong argument to the initialize routine. A common mistake is to reference a global variable instead of referencing the parameters that were actually passed to the `model` function.

---

<div class="post-metadata">

**Author:** ![Khushi\_Bet](https://avatars.discourse-cdn.com/v4/letter/k/3be4f8/32.png) [@Khushi\_Bet](https://community.deeplearning.ai/u/Khushi_Bet)\
**Post date:** [November 9, 2023, 8:59pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/7 "2023-11-09T20:59:55Z")

</div>

```
A = sigmoid(np.dot(w.T, X) +b)

```

ValueError: shapes (1,4) and (1,3) not aligned: 4 (dim 1) != 1 (dim 0)

I get the same error

---

<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:** [November 9, 2023, 9:14pm UTC](https://community.deeplearning.ai/t/week-2-assignment-error/490162/8 "2023-11-09T21:14:26Z")

</div>

Which function are you working on here? If it’s the model function, I added some print statements in my code to show the shapes of the variables and here’s what I see when I run the `model_test` cell:

```auto
type(X_train) <class 'numpy.ndarray'>
X_train.shape (4, 7)
X_test.shape (4, 3)
Y_test.shape (1, 3)
before optimize w.shape (4, 1)
num_iterations 50 learning_rate 0.01
at return in optimize w.shape (4, 1)
in model before predict call w.shape (4, 1)
predictions = [[1. 1. 0. 1. 0. 0. 1.]]
predictions = [[1. 1. 0.]]
All tests passed!

```

So it looks like the shape of your w value is correct, but somehow the X is the wrong shape. So how could that happen?
