Python 3.x 形状[0]和形状[1]在python中做什么?

Python 3.x 形状[0]和形状[1]在python中做什么?,python-3.x,Python 3.x,在python中,[0]返回维度,但在这段代码中,它返回集合的总数。有人能告诉我形状[0]和形状[1]的作品吗 代码: 输出: 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,

在python中,[0]返回维度,但在这段代码中,它返回集合的总数。有人能告诉我形状[0]和形状[1]的作品吗

代码:

输出:

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)

这在计算机视觉中非常常见,第一个维度是示例的数量,第二个和第三个维度提供示例的数据。例如,在计算机视觉的情况下,具有形状(x,y)的n个图像集是非常常见的。在这种情况下,您的训练集的形状为(n,x,y)。数据中的第四个维度是通道数(在本例中为3或RGB)

在您的数据集中,每个图像的高度和宽度都是相同的,因此仅通过第三行即可检索图像的大小:num_px=train_set_x_orig.shape[1]

Related:and。
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)