# NumPy (C1\_W2\_Lab01\_Python\_Numpy\_Vectorization\_Soln)

**URL:** <https://community.deeplearning.ai/t/numpy-c1-w2-lab01-python-numpy-vectorization-soln/179897>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-2\
**Created:** [August 7, 2022, 11:00am UTC](https://community.deeplearning.ai/t/numpy-c1-w2-lab01-python-numpy-vectorization-soln/179897 "2022-08-07T11:00:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohamed\_Mostafa3](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@Mohamed\_Mostafa3](https://community.deeplearning.ai/u/Mohamed_Mostafa3)\
**Post date:** [August 7, 2022, 11:00am UTC](https://community.deeplearning.ai/t/numpy-c1-w2-lab01-python-numpy-vectorization-soln/179897/1 "2022-08-07T11:00:49Z")

</div>

What is the difference between:  
(np.random.random\_sample) and (np.random.rand)

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

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/elemento/32/854_2.png) [@Elemento](https://community.deeplearning.ai/u/Elemento)\
**Post date:** [August 7, 2022, 11:09am UTC](https://community.deeplearning.ai/t/numpy-c1-w2-lab01-python-numpy-vectorization-soln/179897/2 "2022-08-07T11:09:14Z")

</div>

Hey @Mohamed_Mostafa3,  
A look at the documentation of [numpy.random.rand](https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html) is all that you need. In the docs, it is mentioned that:

> This is a convenience function for users porting code from Matlab, and wraps [`random_sample`](https://numpy.org/doc/stable/reference/random/generated/numpy.random.random_sample.html#numpy.random.random_sample). That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like [`numpy.zeros`](https://numpy.org/doc/stable/reference/generated/numpy.zeros.html#numpy.zeros) and [`numpy.ones`](https://numpy.org/doc/stable/reference/generated/numpy.ones.html#numpy.ones).

In simple words, `rand` is simply a wrapper for the `random_sample` function, and the only difference is how you pass the size. `rand` takes the size as separate argument for each dimension, while `random_sample` takes the size as a `tuple`.

In your example, you have passed a single dimension as the size, and hence, no difference is there. Try passing two dimensions as the size, and you will realise the difference yourself. Let us know if this helps.

Cheers,  
Elemento
