Difference between .shape[0] and .shape[1]


In the course, i find sometimes the code is written as m=X.shape[0] and n=w.shape[1]. Can you tell me the difference between these 2 functions, .shape[0] and .shape[1], though both returns the number of columns in an array?

gives the dimensions of the array i,e m,n
if x is an array of 20,30
m = x.shape[o]
gives m = 20
you know indexing starts from 0 in python
let’s see for the same array x
units = X.shape[1]
gives units = 30

Hello @sanjay_shreesha

This is not true.

shape returns a tuple holding the dimensions of the array.

For example: an array X having 4 dimensions: with 2 elements in Dimension 1, 3 elements in Dim 2, 1 element in Dim 3 and 5 elements in dimension 4
X.shape = (2,3,1,5)
X.shape[0] = 2
X.shape[1] = 3
X.shape[2] = 1
X.shape[3] = 5

if X is a 2-d array with m rows and n columns. X.shape = (m,n)
X.shape[0] = m
X.shape[1] = n

Hi Shanup, Understood. Thank you for the explanation!

You are most welcome @sanjay_shreesha