python庫介紹------Numpy

來源:互聯網
上載者:User

標籤:mit   data   integer   lag   for   sig   效能   接下來   http   

NumPy簡介:  NumPy系統是Python的一種開源的數值計算擴充。這種工具可用來儲存和處理大型矩陣,比Python自身的嵌套列表(nested list structure)結構要高效的多(該結構也可以用來表示矩陣(matrix))。

   NumPy(Numeric Python)提供了許多進階的數值編程工具,如:矩陣資料類型、向量處理,以及精密的運算庫。專為進行嚴格的數文書處理而產生。多為很多大型金融公司使用,以及核心的科學計算群組織如:Lawrence Livermore,NASA用其處理一些本來使用C++,Fortran或Matlab等所做的任務。

   NUMPY提供高效能,多維陣列對象和工作工具使用這些數組。它的數組可以用作高效的通用多維容器資料。可以定義任意的資料類型。 1.先來看一下NumPy的資料類型  (1)帶正負號的整數類型    int8: 1-byte       int16: 2-byte    int32: 4-byte    int64: 8-byte

  (2) 不帶正負號的整數類型

    uint8: 1-byte    uint16: 2-byte    uint32: 4-byte   uint64: 8-byte

  (3)C語言整數類型

     int_     intc     intp   short   long   longlong

(4)浮點型floating    布爾型Boolean      複數類型Complex    字串類型str     日期時間類型data  and time  未經處理資料塊Raw data block

  (5)內建資料類型的字元代碼

  •      ?:boolean,                                                                                     例如:
  •    b: signed byte                        i4: 32-bit signed integer
  •      B: unsigned byte                                                                       u2: 16-bit signed integer
  •      i: signed integer                                     =========》                   f8: 64-bit floating-point
  •      u: unsigned integer                                                                   U25: 25-character string
  •      f: floating-point                                                                               V10: 10-byte wide data
  •    c: complex
  •    m: timedelta
  •    M: datetime
  •    O: Python object   
  •    S: (byte) string
  •    U: unicode string
  •    V: raw data (void)

接下來我們將舉例說明NumPy的對數組的各種使用方法:

(1)ndarray  -----多維度數組

 解釋:n--數字number  d--維度dimensional     array--數組


先看一下基本例子:

 

   ndarray具有的屬性:

dtype  shape   ndim  size  itemsize  nbytes  flags  base  

  下面依次介紹屬性使用:

 

   (2)axis

            為具有不止一個維度數組定義軸。二維數組有兩個對應的軸:第一個通過行(軸0)垂直向下運行,以及第二橫跨柱(軸1)水平運行

例如:[ [ [ 0 1 2]

     [ 3 4 5] ]

      [ [ 6 7 8]

      [ 9 10 11] ] ]

sum(axis=0): [ [ 6 8 10] [12 14 16] ]

sum(axis=1): [ [ 3 5 7] [15 17 19] ]

sum(axis=3): [ [ 3 12] [21 30] ]

 

(3)建立多維度數組

  ①通過np.array------這個就是上面說的了,很簡單

②通過函數

函數方法有:empty     zeros  ones  asarray  fromiter  arange      full   eye  random.random  linspace

實現也類似:

(4)多維陣列的重塑:

 

(5)索引和切片

 

整數數組索引可以構造任意數組

 

使用來自另一個數組的資料

 

  

python庫介紹------Numpy

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.