Reputation: 109
In python shape[0] returns the dimension but in this code it is returning total number of set. Please can someone tell me work of shape[0] and shape[1]?
Code:
m_train = train_set_x_orig.shape[0]
m_test = test_set_x_orig.shape[0]
num_px = train_set_x_orig.shape[1]
print ("Number of training examples: m_train = " + str(m_train))
print ("Number of testing examples: m_test = " + str(m_test))
print ("Height/Width of each image: num_px = " + str(num_px))
print ("Each image is of size: (" + str(num_px) + ", " + str(num_px) + ", 3)")
print ("train_set_x shape: " + str(train_set_x_orig.shape))
print ("train_set_y shape: " + str(train_set_y.shape))
print ("test_set_x shape: " + str(test_set_x_orig.shape))
print ("test_set_y shape: " + str(test_set_y.shape))
Output:
Number of training examples: m_train = 209
Number of testing examples: m_test = 50
Height/Width of each image: num_px = 64
Each image is of size: (64, 64, 3)
train_set_x shape: (209, 64, 64, 3)
train_set_y shape: (1, 209)
test_set_x shape: (50, 64, 64, 3)
test_set_y shape: (1, 50)
Upvotes: 3
Views: 15167
Reputation: 78
This is quite common in computer vision the first dimension being the number of examples, the second and third provide the data of the examples. In the case of computer vision for example it is quite common to have a set of n images with shape (x,y). In this case your training set will be of the shape (n,x,y). The fourth dimension in your data is the number of channels (3, or RGB in this case).
In your dataset the height and the width of each image is the same and thus the size of the image can be retrieved merely by the third line: num_px = train_set_x_orig.shape[1]
Upvotes: 4