python:shape

python:shape,第1张

shape函数用来了解数组的结构

import numpy as np
#对于一维的数据
data = np.array([1,2,3,4,5,6,7,8])
print(data.shape)
print(type(data.shape))
print(data.shape[0])

输出:
(8,)

8

#对于二维的数据
data = np.array([[1,2,3,4],[5,6,7,8]])
print(data.shape)
print(type(data.shape))
print(data.shape[0])

输出:
(2, 4)

2

#对于三维的数据
data = np.array([[[1,2], [3, 4]],[[5,6],[7,8]]])
print(data.shape)
print(type(data.shape))
print(data.shape[0])

输出:
(2, 2, 2)

2

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/796666.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存