一周学会Pandas2 Python数据处理与分析-NumPy数组属性
锋哥原创的Pandas2 Python数据处理与分析 视频教程:
2025版 Pandas2 Python数据处理与分析 视频教程(无废话版) 玩命更新中~_哔哩哔哩_bilibili
下面是数组的一些常见属性。
属性名 | 含义 |
---|---|
dtype | 数组中元素的类型 |
ndim | 数组的维度 |
size | 所有数据的长度,比如mn维的二维数组,其size就是mn |
itemsize | 表示一个元素所占的字节的多少 |
shape | 数组的形状 |
代码示例:
# 创建三维数组
a3 = np.array([[[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[9, 10, 11], [12, 13, 14], [15, 16, 17]],
[[18, 19, 20], [21, 22, 23], [24, 25, 26]]])
print(a3)
print('数组的维度:', a3.ndim)
print('数组的形状:', a3.shape)
print('数据的长度:', a3.size)
print('数组中的元素的类型:', a3.dtype)
print('数组中的每个元素所占的字节:', a3.itemsize)
运行输出:
[[[ 0 1 2]
[ 3 4 5]
[ 6 7 8]]
[[ 9 10 11]
[12 13 14]
[15 16 17]]
[[18 19 20]
[21 22 23]
[24 25 26]]]
数组的维度: 3
数组的形状: (3, 3, 3)
数据的长度: 27
数组中的元素的类型: int64
数组中的每个元素所占的字节: 8