首页 > 其他 > 详细

ndarry对象的属性

时间:2020-03-29 22:12:47      阅读:74      评论:0      收藏:0      [点我收藏+]
 1 #导入numpy
 2 import numpy as np 
 3 #创建一维数组
 4 a = np.array([1,2,3,4])
 5 print(a)
 6 #创建二维数组
 7 b = np.random.randint(4,10,size=(2,3))
 8 print(b)
 9 #创建三维数组
10 c = np.random.randn(2,3,4)
11 print(c)
12 #ndim属性
13 print(ndim:,a.ndim,b.ndim,c.ndim)
14 #shape属性
15 print(shape:,a.shape,b.shape,c.shape)
16 #dtype属性
17 print(dtype:,a.dtype,b.dtype,c.dtype)
18 #size元素的总个数
19 print(size:,a.size,b.size,c.size)
20 #itemsize每个元素所占的字节
21 print(itemsize:,a.itemsize,b.itemsize,c.itemsize)
 1 [1 2 3 4]
 2 [[4 4 8]
 3  [8 6 6]]
 4 [[[-0.04322546  0.37600869 -0.84201739  0.3652211 ]
 5   [ 0.30035931  0.54828284  0.26615364 -0.49428617]
 6   [ 0.10315291  0.07493424  0.27695642  0.1780474 ]]
 7 
 8  [[ 0.46234703  0.07898361 -1.2045445   0.61272457]
 9   [-0.15794512  0.64909964  0.02984023 -0.57428904]
10   [ 0.03801586 -1.31788363  0.64976292  1.07791379]]]
11 ndim: 1 2 3
12 shape: (4,) (2, 3) (2, 3, 4)
13 dtype: int32 int32 float64
14 size: 4 6 24
15 itemsize: 4 4 8

 

ndarry对象的属性

原文:https://www.cnblogs.com/monsterhy123/p/12594968.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!