# NumPy array shape annotation / definition

**URL:** <https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671>\
**Category:** Supervised ML: Regression and Classification\
**Created:** [June 18, 2024, 9:12pm UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671 "2024-06-18T21:12:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rollther](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rollther/32/90265_2.png) [@rollther](https://community.deeplearning.ai/u/rollther)\
**Post date:** [June 18, 2024, 9:12pm UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/1 "2024-06-18T21:12:29Z")

</div>

In the week 2 lab following Vectorisation part 2, we use NumPy to view the shape of an array, for various arrays. I am confused because for a 1-dimensional array, calling the shape using .shape results in something like (n,), or (4,) when the number of columns is 4, whereas for 2-dimensional arrays the shape is printed in the format (m, n) where m is the number of rows and n the number of columns. I would therefore expect the result of . shape called on a 1-dimensional array to be in the format (, n) rather than (n,). Or for the above example (, 4).

Vectorisation : [Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera](https://www.coursera.org/learn/machine-learning/ungradedLab/zadmO/optional-lab-python-numpy-and-vectorization)

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [June 18, 2024, 9:15pm UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/2 "2024-06-18T21:15:38Z")

</div>

There really isn’t a standard for the layout of the dimensions. Sometimes you’ll see (m,n) and sometimes it’s (n,m).

Even within a specific course or notebook, it could vary.

So you just have to look at how the dataset is organized, and adapt as necessary.

---

<div class="post-metadata">

**Author:** ![ntcuong2103](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@ntcuong2103](https://community.deeplearning.ai/u/ntcuong2103)\
**Post date:** [June 19, 2024, 10:52am UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/3 "2024-06-19T10:52:35Z")

</div>

For the shape of an array, it should be note that each of the shape is corresponding to the dimension of the array. For 1-d array, the dimensions count from 0 (first dimension), then the shape (N,) or shape at 0 is N.

---

<div class="post-metadata">

**Author:** ![rollther](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/rollther/32/90265_2.png) [@rollther](https://community.deeplearning.ai/u/rollther)\
**Post date:** [June 19, 2024, 11:48am UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/4 "2024-06-19T11:48:45Z")

</div>

That makes sense, thanks

---

<div class="post-metadata">

**Author:** ![jiyanbaran](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jiyanbaran](https://community.deeplearning.ai/u/jiyanbaran)\
**Post date:** [June 21, 2024, 8:58pm UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/5 "2024-06-21T20:58:59Z")

</div>

Since it is related, may I kindly ask what is the difference between

a = np.zeros(4) and a = np.zeros((4,))?

Thanks a lot.

---

<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:** [June 22, 2024, 12:54am UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/6 "2024-06-22T00:54:27Z")

</div>

Hello, @jiyanbaran,

There is no difference. Both (4, ) and 4 convey the meaning of a 1D array of 4 elements.

Cheers,  
Raymond

---

<div class="post-metadata">

**Author:** ![jiyanbaran](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@jiyanbaran](https://community.deeplearning.ai/u/jiyanbaran)\
**Post date:** [June 22, 2024, 1:28pm UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/7 "2024-06-22T13:28:15Z")

</div>

Hello @rmwkwok

Thanks for your help!

Regards  
Jiyan

---

<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:** [June 23, 2024, 12:13am UTC](https://community.deeplearning.ai/t/numpy-array-shape-annotation-definition/649671/8 "2024-06-23T00:13:54Z")

</div>

No problem, Jiyan @jiyanbaran.

Cheers,  
Raymond
