不积跬步,无以至千里;不积小流,无以成江海。

Dean's blog

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

NumPy数组的属性

import numpy as np

x1 = np.random.randint(10, size=6)             #一维数组
x2 = np.random.randint(10, size=(3, 4))       #二维数组
x3 = np.random.randint(10, size=(3, 4, 5))   #三维数组

#数组的维度
print("x3 ndim:", x3.ndim)             #x3 ndim: 3
#数组每个维度的大小
print("x3 shape:", x3.shape)         #x3 shape: (3, 4, 5)
#数组的总大小(个数)
print("x3 size:", x3.size)                #x3 size: 60
#数组数据类型
print("x3 dtype:", x3.dtype)           #x3 dtype: int32
#数组元素字节大小
print("x3 item size:", x3.itemsize) #x3 item size: 4
#数组总字段大小
print("x3 nbytes:", x3.nbytes)       #x3 nbytes: 240

 

不允许评论
粤ICP备17049187号-1