numpy的常用方法3-5

 1 np.arange(15)     #生成15个自然数
 2 #结果
 3 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
 4 
 5 result = np.arange(15).reshape(3,5)  #给15个数分成3行5列
 6 print(result)
 7 result.ndim                                      #result这个变量的维度 
 8 
 9 #结果
10 
11 [[ 0  1  2  3  4]
12  [ 5  6  7  8  9]
13  [10 11 12 13 14]]                           #3行5列
14 
15 2                                                     #变量是2维的
16 
17 result.dtype.name #查看result里面元素类型
18 result.dtype.name #和上面效果类似
19 
20 #结果
21 dtype('int64')
22 'int64'
23 
24 result.size
25 #结果
26 15   #一共15个元素
np.ones([4,6])                       #4行六列全部拿   1  去填充
#结果
array([[1., 1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1., 1.]])

np.zeros([4,6])    
#结果
array([[0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0.]])               #4行六列全部拿0去填充

 

 

posted @ 2018-04-11 18:24  移动的城市  阅读(151)  评论(0)    收藏  举报