首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >shape[0]和shape[1]在python中做什么?

shape[0]和shape[1]在python中做什么?
EN

Stack Overflow用户
提问于 2018-07-21 12:09:10
回答 1查看 9.8K关注 0票数 3

在python形状中,返回维度,但在这段代码中,它返回的集合总数。请有人告诉我形状和shape1的工作

代码:

代码语言:javascript
复制
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))

输出:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-21 12:18:37

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

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51455927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档