热线电话:13121318867

登录
2018-11-13 阅读量: 767
数组的属性整理

定义三个随机的数组: 一个一维数组、

一个二维数组和一个三维数组。

In[1]: import numpy as np

np.random.seed(0) # 设置随机数种子

x1 = np.random.randint(10, size=6) # 一维数组

x2 = np.random.randint(10, size=(3, 4)) # 二维数组

x3 = np.random.randint(10, size=(3, 4, 5)) # 三维数组

每个数组有 nidm(数组的维度) 、 shape(数组每个维度的大小) 和

size(数组的总大小) 属性:

In[2]: print("x3 ndim: ", x3.ndim)
print("x3 shape:", x3.shape)
print("x3 size: ", x3.size)
x3 ndim: 3
x3 shape: (3, 4, 5)
x3 size: 60

另外一个有用的属性是 dtype, 它是数组的数据类型

In[3]: print("dtype:", x3.dtype)
dtype: int64

0.0000
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子