numpy--1.2数组属性

种子值seed、维度ndim、形状shape、尺寸size、数据类型dtype、元素字节大小itemsize;总字节大小nbytes

1.设置种子值可以确保每次程序执行时都可以生成同样的随机数组:

  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))  # 三维数组

2.ndim--数组的维度;shape--数组没个维度的大小;size--数组的总大小

  x3的 ndim: 3

     shape: (3, 4, 5)

     size: 60

3.dtype--数组的数据类型

  x3的dtype: int64

4.itemsize--每个元素字节大小;nbytes--数组总字节大小

  x3的 itemsize: 8 bytes

     nbytes: 480 bytes

一般来说,nbytes = itemsize * size

 

posted @ 2020-05-15 14:44  编程小书童  阅读(155)  评论(0编辑  收藏  举报