如何获取Numpy数据的基本属性

1. 创建数组

import numpy as np
a1 = np.array([[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,27,28,29,30],
               [31,32,33,34,35,36]])
print(a1)
结果:
[[ 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 27 28 29 30]
 [31 32 33 34 35 36]]

2. 数组形状

import numpy as np
a1 = np.array([[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,27,28,29,30],
               [31,32,33,34,35,36]])
print(a1.shape)
结果:
(6, 6)

3. 数组大小

import numpy as np
a1 = np.array([[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,27,28,29,30],
               [31,32,33,34,35,36]])
print(a1.size)
结果
36

4. 数组维数

import numpy as np
a1 = np.array([[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,27,28,29,30],
               [31,32,33,34,35,36]])
print(a1.ndim)
结果:
2

https://www.jianshu.com/p/896918f3184b

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
Python
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论