# TypeError in Week Four Lab Assignment 3

**URL:** <https://community.deeplearning.ai/t/typeerror-in-week-four-lab-assignment-3/767807>\
**Category:** Linear Algebra for Machine Learning and Data Sc...\
**Tags:** week-module-4\
**Created:** [February 11, 2025, 2:13am UTC](https://community.deeplearning.ai/t/typeerror-in-week-four-lab-assignment-3/767807 "2025-02-11T02:13:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Brown](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jeffrey\_Brown](https://community.deeplearning.ai/u/Jeffrey_Brown)\
**Post date:** [February 11, 2025, 2:13am UTC](https://community.deeplearning.ai/t/typeerror-in-week-four-lab-assignment-3/767807/1 "2025-02-11T02:13:34Z")

</div>

I am receiving a TypeError that I can’t resolve. Here is my error message:

* * *

TypeError Traceback (most recent call last)  
 in   
----\> 1 X = center\_data(imgs\_flatten)  
2 plt.imshow(X[0].reshape(64,64), cmap=‘gray’)

in center\_data(Y)  
10 ### START CODE HERE ###  
11 mean\_vector = Y.mean(axis=0, dtype=np.float64)  
—\> 12 mean\_matrix = Y.repeat(mean\_vector, Y.shape[0])  
13 # use np.reshape to reshape into a matrix with the same size as Y. Remember to use order=‘F’  
14 mean\_matrix = Y.reshape(mean\_matrix, Y.shape, order=‘F’)

TypeError: Cannot cast array data from dtype(‘float64’) to dtype(‘int64’) according to the rule ‘safe’

I would appreciate any help. Thank you.

---

<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:** [February 11, 2025, 4:25am UTC](https://community.deeplearning.ai/t/typeerror-in-week-four-lab-assignment-3/767807/2 "2025-02-11T04:25:24Z")

</div>

> [@Jeffrey\_Brown](#):
>
> mean\_matrix = Y.repeat(mean\_vector, Y.shape[0])

Using `repeat()` as a “method” of Y, means you are saying you want to repeat Y and then the first argument is the “repeat count”, which needs to be an integer. But you are feeding it an array of 64 bit floats as the repeat count.

But it’s a mistake on two levels: Y is not the thing you want to repeat, is it?

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Brown](https://avatars.discourse-cdn.com/v4/letter/j/4af34b/32.png) [@Jeffrey\_Brown](https://community.deeplearning.ai/u/Jeffrey_Brown)\
**Post date:** [February 12, 2025, 1:34am UTC](https://community.deeplearning.ai/t/typeerror-in-week-four-lab-assignment-3/767807/3 "2025-02-12T01:34:49Z")

</div>

Thanks Paul!
