python 資料分析 Numpy(Numerical Python Basic)

來源:互聯網
上載者:User

標籤:asi   技術   sum   import   pytho   技術分享   print   out   cal   

 

 

 # 匯入numpy 模組 
1 import numpy as np 10 a = np.random.random((2,4)) 11 a 12 Out[5]: 13 array([[0.20974732, 0.73822026, 0.82760722, 0.050551 ], 14 [0.77337155, 0.06521922, 0.55524187, 0.59209907]])

# 求矩陣所有資料的和,最小值,最大值 22 np.sum(a) 23 Out[7]: 3.812057513268513 24 np.min(a) 25 Out[8]: 0.05055099733013646 26 np.max(a) 27 Out[9]: 0.8276072194278252 28 print("a=",a) 29 a= [[0.20974732 0.73822026 0.82760722 0.050551 ] 30 [0.77337155 0.06521922 0.55524187 0.59209907]]

# axis=0 代表列, axis=1代表行
 31 print("min",np.min(a)) 32 min 0.05055099733013646
#求每列當中的最小值 33 print("lmin:",np.min(a,axis=0)) 34 lmin: [0.20974732 0.06521922 0.55524187 0.050551 ] 35 print("lmin:",np.min(a,axis=1)) 36 lmin: [0.050551 0.06521922] 37 print("sum:",np.sum(a,axis=1)) 38 sum: [1.8261258 1.98593171]

# reshape 資料, 3行4列 39 A = np.arange(2,14).reshape(3,4) 40 A 41 Out[16]: 42 array([[ 2, 3, 4, 5], 43 [ 6, 7, 8, 9], 44 [10, 11, 12, 13]])

# ndarray中最小值,最大值的序號 45 print(np.argmin(A)) 46 0 47 print(np.argmax(A)) 48 11 49 print(np.mean(A)) 50 7.5 51 print(np.average(A)) 52 7.5 53 print(A.mean()) 54 7.5
# cumsum 迭代相加 69 A 70 Out[24]: 71 array([[ 2, 3, 4, 5], 72 [ 6, 7, 8, 9], 73 [10, 11, 12, 13]]) 81 print(A.cumsum()) 82 [ 2 5 9 14 20 27 35 44 54 65 77 90] 83 A 84 Out[27]: 85 array([[ 2, 3, 4, 5], 86 [ 6, 7, 8, 9], 87 [10, 11, 12, 13]])
# clip(a, a_min, a_max) 將ndarray中的資料進行判斷,小於a_min的值都賦值為a_min, 大於a_max的都賦值a_max,在這之間的值不變。 88 print(np.clip(A,5,8)) 89 [[5 5 5 5] 90 [6 7 8 8] 91 [8 8 8 8]]
# 判斷ndarray階數,幾維向量
99 A.ndim100 Out[30]: 2101 A102 Out[31]: 103 array([[ 2, 3, 4, 5],104 [ 6, 7, 8, 9],105 [10, 11, 12, 13]])106 A.ndim107 Out[32]: 2108 a109 Out[33]: 110 array([[0.20974732, 0.73822026, 0.82760722, 0.050551 ],111 [0.77337155, 0.06521922, 0.55524187, 0.59209907]])112 a.ndim113 Out[34]: 2114 A115 Out[35]: 116 array([[ 2, 3, 4, 5],117 [ 6, 7, 8, 9],118 [10, 11, 12, 13]])

 

python 資料分析 Numpy(Numerical Python Basic)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.