<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      一、簡介

      ?NumPy(Numerical Python) 是用于科學(xué)計(jì)算及數(shù)據(jù)處理的Python擴(kuò)展程序庫,支持大量的維度數(shù)組與矩陣運(yùn)算,此外也針對數(shù)組運(yùn)算提供大量的數(shù)學(xué)函數(shù)庫。

      二、數(shù)據(jù)結(jié)構(gòu)

      ?numpy基本數(shù)據(jù)結(jié)構(gòu)類型為Ndarray對象,其為可存放同類型元素的多維數(shù)組。

      • 創(chuàng)建ndarray語法如下
        numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)

      示例

      使用前導(dǎo)入numpy包

      import numpy as np
      
      • 傳入多維列表
      a = np.array([[0,  1],  [2,  3]])  
      print (a)
      # 輸出:[[0  1] 
      #       [2  3]]
      
      • 指定維度
      a = np.array([1, 2, 3], ndmin =  2)  
      print (a)
      #輸出: [[1 2 3]]
      

      -包含的基本屬性

      屬性 說明
      ndarray.ndim 秩,即軸的數(shù)量或維度的數(shù)量
      ndarray.shape 數(shù)組的維度,對于矩陣,n 行 m 列
      ndarray.size 數(shù)組元素的總個數(shù),相當(dāng)于 .shape 中 n*m 的值
      ndarray.dtype ndarray 對象的元素類型
      ndarray.itemsize ndarray 對象中每個元素的大小,以字節(jié)為單位
      ndarray.flags ndarray 對象的內(nèi)存信息
      ndarray.real ndarray元素的實(shí)部
      ndarray.imag ndarray 元素的虛部
      ndarray.data 包含實(shí)際數(shù)組元素的緩沖區(qū),由于一般通過數(shù)組的索引獲取元素,所以通常不需要使用這個屬性。

      三、花式創(chuàng)建narray的9種方法

      1. 創(chuàng)建指定shape的空narray
        numpy.empty(shape, dtype = float, order = 'C') # order可取"C"(行優(yōu)先)和"F"(列優(yōu)先)。
      • 示例
      x = np.empty([3,2], dtype = int)
      print (x)
      

      輸出: [[ 6917529027641081856 5764616291768666155] [ 6917529027641081859 -5764598754299804209] [ 4497473538 844429428932120]]
      2. 創(chuàng)建全0的narray
      numpy.zeros(shape, dtype = float, order = 'C')

      • 示例
      x = np.zeros((5,), dtype = np.int) 
      print(x)
      

      輸出: [0 0 0 0 0]
      3. 創(chuàng)建全1的narray
      numpy.ones(shape, dtype = float, order = 'C')

      • 示例
      x = np.ones(5) 
      print(x)
      

      輸出: [1. 1. 1. 1.]

      1. 從range創(chuàng)建narray
        numpy.arange(start = 0, stop, step = 1, dtype =None)
      • 示例
      x = np.arange(5)  
      print (x)
      

      輸出: [0 1 2 3 4]
      5.創(chuàng)建等差數(shù)列填充的narray
      np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
      # endpoint 是否包含最后一個數(shù)
      retstep 是否顯示步長

      • 示例1
      a = np.linspace(1,10,10)
      print(a)
      

      輸出: [1 2 3 4 5 6 7 8 9 10]

      • 示例2
      a = np.linspace(1,10,10, retstep=True)
      print(a)
      

      輸出是一個元組: (array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]), 1.0)
      6. 創(chuàng)建等比數(shù)列填充的narray
      np.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)
      base 參數(shù)意思是取對數(shù)的時候 log 的下標(biāo)。

      參數(shù) 描述
      start 序列的起始值為:base ** start
      stop 序列的終止值為:base ** stop。如果endpoint為true,該值包含于數(shù)列中
      num 要生成的等步長的樣本數(shù)量,默認(rèn)為50
      endpoint 該值為 true 時,數(shù)列中中包含stop值,反之不包含,默認(rèn)是True。
      base 對數(shù) log 的底數(shù)。
      dtype ndarray 的數(shù)據(jù)類型
      • 示例1
      # 默認(rèn)底數(shù)是 10
      a = np.logspace(1.0,  2.0, num =  10)  
      print (a)
      

      輸出: [ 10. 12.91549665 16.68100537 21.5443469 27.82559402 35.93813664 46.41588834 59.94842503 77.42636827 100. ]

      • 示例2
      a = np.logspace(0,9,10,base=2)
      print (a)
      

      輸出: [ 1. 2. 4. 8. 16. 32. 64. 128. 256. 512.]
      7. 從已有數(shù)組創(chuàng)建narray
      numpy.asarray(a, dtype = None, order = None)

      參數(shù) 描述
      a 任意形式的輸入?yún)?shù),可以是,列表, 列表的元組, 元組, 元組的元組, 元組的列表,多維數(shù)組
      dtype 數(shù)據(jù)類型,可選
      order 可選,有"C"和"F"兩個選項(xiàng),分別代表,行優(yōu)先和列優(yōu)先,在計(jì)算機(jī)內(nèi)存中的存儲元素的順序。
      • 示例
      x =  [1,2,3] 
      a = np.asarray(x)  
      print (a)
      

      輸出: [1 2 3]
      8. 從buffer流創(chuàng)建narray
      numpy.frombuffer(buffer, dtype = float, count = -1, offset = 0)

      參數(shù) 描述
      buffer 可以是任意對象,會以流的形式讀入。
      dtype 返回?cái)?shù)組的數(shù)據(jù)類型,可選
      count 讀取的數(shù)據(jù)數(shù)量,默認(rèn)為-1,讀取所有數(shù)據(jù)。
      offset 讀取的起始位置,默認(rèn)為0。
      • 示例
      s =  b'Hello World' 
      a = np.frombuffer(s, dtype =  'S1')  
      print (a)
      

      輸出: [b'H' b'e' b'l' b'l' b'o' b' ' b'W' b'o' b'r' b'l' b'd']
      9. 從迭代對象創(chuàng)建narray
      numpy.fromiter(iterable, dtype, count=-1)

      參數(shù) 描述
      iterable 可迭代對象
      dtype 返回?cái)?shù)組的數(shù)據(jù)類型
      count 讀取的數(shù)據(jù)數(shù)量,默認(rèn)為-1,讀取所有數(shù)據(jù)
      • 示例
      # 使用 range 函數(shù)創(chuàng)建列表對象  
      list=range(5)
      it=iter(list)
       
      # 使用迭代器創(chuàng)建 ndarray 
      x=np.fromiter(it, dtype=float)
      print(x)
      

      輸出: [0. 1. 2. 3. 4.]

      注:整理自菜鳥教程

       posted on 2022-03-17 17:21  快樂的大李  閱讀(283)  評論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 国产精品任我爽爆在线播放6080| 377P欧洲日本亚洲大胆| 免费国产一区二区不卡| 一本加勒比hezyo无码人妻| av中文无码韩国亚洲色偷偷| 亚洲色大成网站www永久男同| 99riav国产精品视频| 柳河县| 综合在线 亚洲 成人 欧美| 免费无遮挡毛片中文字幕| 亚洲成人一区| 国产成人精品日本亚洲专区6| 亚洲人成亚洲人成在线观看| 日韩中文字幕人妻精品| 中文字幕精品亚洲二区| 国产精品女人毛片在线看| 留坝县| 国产精品一起草在线观看| 欧美影院成年免费版| 高清免费毛片| 国产不卡一区在线视频| 加勒比色综合久久久久久久久| 亚洲AV永久无码一区| 娇妻玩4p被三个男人伺候| 亚洲AVAV天堂AV在线网阿V| 亚洲精品无码久久一线| 亚洲精品一区二区在线播| 337p西西人体大胆瓣开下部| 丝袜美腿亚洲综合第一页| 黄色A级国产免费大片视频| 客服| 国产片一区二区三区视频| 亚洲av永久无码天堂影院| 尤物国精品午夜福利视频| 精品亚洲国产成人av| 国产99久久久国产精品~~牛| 99久久免费精品色老| 一区二区视频观看在线| 精品一区二区三区在线观看l| 久久精品久久黄色片看看| 乱码中文字幕|