# Question about data in Numpy array

**URL:** <https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-1\
**Created:** [July 31, 2023, 6:49am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926 "2023-07-31T06:49:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nguyen\_Thien\_An](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@Nguyen\_Thien\_An](https://community.deeplearning.ai/u/Nguyen_Thien_An)\
**Post date:** [July 31, 2023, 6:49am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/1 "2023-07-31T06:49:06Z")

</div>

Could anyone tell me the difference between np.array([1, 2, 3]) and np.([[1, 2 ,3] ]).  
Why in the lecture, the prof uses the later one rather than the first one?  
Thank you so much!

---

<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:** [July 31, 2023, 6:57am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/2 "2023-07-31T06:57:06Z")

</div>

Check this:

```auto
arr1 = np.array([1, 2, 3])
print("arr1:", arr1)
print("Shape of arr1:", arr1.shape)  

arr2 = np.array([[1, 2, 3]])
print("arr2:", arr2)
print("Shape of arr2:", arr2.shape)  

```

And this is the result:

```auto
arr1: [1 2 3]
Shape of arr1: (3,)

arr2: [[1 2 3]]
Shape of arr2: (1, 3)

```

So, do you see the difference?

---

<div class="post-metadata">

**Author:** ![Nguyen\_Thien\_An](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@Nguyen\_Thien\_An](https://community.deeplearning.ai/u/Nguyen_Thien_An)\
**Post date:** [July 31, 2023, 7:45am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/3 "2023-07-31T07:45:30Z")

</div>

Oh, I see. But why would we need to use vector with shape of (1, 3) rather than (3, 1)?

---

<div class="post-metadata">

**Author:** ![Nguyen\_Thien\_An](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@Nguyen\_Thien\_An](https://community.deeplearning.ai/u/Nguyen_Thien_An)\
**Post date:** [July 31, 2023, 7:46am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/4 "2023-07-31T07:46:07Z")

</div>

Or is it because of multiple features?

---

<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:** [July 31, 2023, 7:51am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/5 "2023-07-31T07:51:52Z")

</div>

> [@Nguyen\_Thien\_An](#):
>
> But why would we need to use vector with shape of (1, 3) rather than (3, 1)?

It depends on how you shape your input data.

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 31, 2023, 7:58am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/6 "2023-07-31T07:58:54Z")

</div>

Hello @Nguyen_Thien_An,

The shape of `np.array([1, 2, 3])` is `(3, )` instead of `(3, 1)`.

`(3, )` is a 1-dimensional array, whereas `(3, 1)` is a 2-dimensional array. This might be another subtle difference that we want to notice.

`np.array([[1,], [2,], [3,] ])` is a `(3, 1)` array.

In layman language, `(3, 1)` represents 3 rows and 1 column. `(1, 3)` represents 1 row and 3 columns. In the MLS convention, if it is a dataset array, we are used to represent 1 sample in a row and its features by columns. However, sometimes, if we have only one feature, we might want to use `(3, )` instead. This is what @saifkhanengr meant.

Therefore, it is a convention. In our specialization (MLS), we have the above convention, but in other places, the convention might be different, and we need to pay attention to this details.

Btw, you didn’t share with us in which lecture you found that notation, so here it is just some very general explanation.

Cheers,  
Raymond

---

<div class="post-metadata">

**Author:** ![Nguyen\_Thien\_An](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@Nguyen\_Thien\_An](https://community.deeplearning.ai/u/Nguyen_Thien_An)\
**Post date:** [July 31, 2023, 8:11am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/7 "2023-07-31T08:11:54Z")

</div>

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Nguyen\_Thien\_An](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@Nguyen\_Thien\_An](https://community.deeplearning.ai/u/Nguyen_Thien_An)\
**Post date:** [July 31, 2023, 8:19am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/8 "2023-07-31T08:19:30Z")

</div>

I know this is a bit irrelevant, but why we use row vector for multiple features whereas column vector when passing in value to the neural network. Is this the convention?  
Thanks!

---

<div class="post-metadata">

**Author:** ![rmwkwok](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rmwkwok/32/126977_2.png) [@rmwkwok](https://community.deeplearning.ai/u/rmwkwok)\
**Post date:** [July 31, 2023, 8:23am UTC](https://community.deeplearning.ai/t/question-about-data-in-numpy-array/402926/9 "2023-07-31T08:23:09Z")

</div>

Generally, when we pass data into a neural network, we use a 2-D array, where one row represents a sample, and one column represents a feature. This is the MLS convention.

However, if you see 1-D array, this is some special case which can either means “one sample of multiple features” or “multiple samples of one feature”, and we will need to read the context to determine what it is.

2-D array is the standard representation, and it works for multiple samples with multiple features. 1-D is for the special cases.

Again, I don’t know which slide you are asking, so it is just very general discussion 😉
