numpy的课程学习二

numpy的课程学习二

# 笔记
#1. 创建全1的维数组用np.ones([2,3],order="C") (中括号表示维度)
#2. 自定义数字填充用np.full((2,3),fill_value = 3) 括号表示维度,fill_value表示填充的值
#3. 创建对角为1矩阵用np.eye((2,3),k=1) 括号表示维度,k的值表示从第几列(从左到右)开始为1,k=-1表示(从上到下第二个)
#4. 创建等差数列用np.linspace(1,100,15) 表示包括起始位置和终止位置之间去15个等差数列的数
#5. 创建一维的数据用np.arange(start,stop,step) 表示从开始位置不包括结束位置取步长为step的整数
#6. 创建随机维度整数 np.random.randint(10,100,size=(2,3)) size表示维度
#7. 创建正态分布的数据np.random.randn(10,3,4)表示生成10个三行四列的数据
#8. 创建随机0-1之间的小数用np.random.random((10,3)),维度要用小括号括起来,否则会报错
import numpy as np
one_array = np.ones([2,3],order="F") # order表示存储方式
one_array
array([[1., 1., 1.],
       [1., 1., 1.]])
np.full((2,3),fill_value=10)
array([[10, 10, 10],
       [10, 10, 10]])
np.eye(4,k=1)
array([[0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.],
       [0., 0., 0., 0.]])
np.linspace(1,100,15)
array([  1.        ,   8.07142857,  15.14285714,  22.21428571,
        29.28571429,  36.35714286,  43.42857143,  50.5       ,
        57.57142857,  64.64285714,  71.71428571,  78.78571429,
        85.85714286,  92.92857143, 100.        ])
np.arange(10,step=2)
array([0, 2, 4, 6, 8])
np.arange(3,20,3)
array([ 3,  6,  9, 12, 15, 18])
np.random.randint(10,100,size=(2,3))
array([[24, 19, 84],
       [82, 45, 99]])
np.random.randn(10,3,4)
array([[[ 1.58369179,  1.42303258,  0.88819411,  0.63833451],
        [-0.78686923,  1.56738507,  1.7172825 , -0.16730439],
        [ 0.59016109, -1.25896746,  1.07261354,  1.09432537]],

       [[ 0.1125571 ,  0.7180809 , -0.51703986,  0.23129182],
        [ 1.23954611, -0.52115147,  0.8639836 ,  0.53928262],
        [-0.10362021, -0.52619911,  1.38258495,  0.60851597]],

       [[ 0.97404312, -0.74997834, -0.44052106, -0.66034319],
        [-0.25173983,  1.38116703,  1.8612758 ,  1.74102855],
        [-1.05501604,  1.52146139, -0.45359433, -0.50436895]],

       [[ 0.66153401, -3.19061624,  2.89650019,  0.25149237],
        [-0.28092117, -0.12755441, -0.78776785,  0.64300246],
        [ 0.07175466,  1.04350169,  0.10472045,  0.35148533]],

       [[ 0.51126854,  1.13468762,  1.26469829, -1.17413825],
        [-0.30884398, -1.60045753,  2.29348318,  1.14705215],
        [-0.13183601,  0.33142396, -1.54939638,  0.99063152]],

       [[ 0.510777  , -1.76104264, -0.73007793,  0.57137522],
        [-3.06108689,  0.58566944,  0.5593007 ,  0.4896721 ],
        [-0.0360543 ,  0.52091961, -0.53082385,  0.21792386]],

       [[-0.38155656, -0.11654561, -0.04776588, -1.7082345 ],
        [ 0.31969823, -0.46259766, -1.34005927,  1.08148054],
        [ 0.74527479,  1.11816672, -0.69034193, -0.109475  ]],

       [[ 0.54794889, -1.03139858, -1.62371554,  0.82631335],
        [-2.01810778, -1.70978601, -1.05606447,  0.83063485],
        [ 0.65893224,  0.82930533, -1.16182606,  0.18053996]],

       [[ 0.3892796 , -0.25463191,  0.52248044, -0.71065632],
        [ 0.18266089, -0.06587436, -0.40788761,  0.85430646],
        [ 0.56759129, -0.07170791, -0.43569392,  2.21859482]],

       [[-0.94588188,  0.84308949,  1.8816113 , -0.07954098],
        [-0.03295456, -1.71031548, -0.46404446,  0.15589721],
        [ 0.81575382, -0.47360413,  0.00893313, -0.58134254]]])
np.random.rand(10,3,4)
array([[[0.09045935, 0.30070006, 0.11398436, 0.82868133],
        [0.04689632, 0.62628715, 0.54758616, 0.819287  ],
        [0.19894754, 0.8568503 , 0.35165264, 0.75464769]],

       [[0.29596171, 0.88393648, 0.32551164, 0.1650159 ],
        [0.39252924, 0.09346037, 0.82110566, 0.15115202],
        [0.38411445, 0.94426071, 0.98762547, 0.45630455]],

       [[0.82612284, 0.25137413, 0.59737165, 0.90283176],
        [0.53455795, 0.59020136, 0.03928177, 0.35718176],
        [0.07961309, 0.30545992, 0.33071931, 0.7738303 ]],

       [[0.03995921, 0.42949218, 0.31492687, 0.63649114],
        [0.34634715, 0.04309736, 0.87991517, 0.76324059],
        [0.87809664, 0.41750914, 0.60557756, 0.51346663]],

       [[0.59783665, 0.26221566, 0.30087131, 0.02539978],
        [0.30306256, 0.24207588, 0.55757819, 0.56550702],
        [0.47513225, 0.29279798, 0.06425106, 0.97881915]],

       [[0.33970784, 0.49504863, 0.97708073, 0.44077382],
        [0.31827281, 0.51979699, 0.57813643, 0.85393375],
        [0.06809727, 0.46453081, 0.78194912, 0.71860281]],

       [[0.58602198, 0.03709441, 0.35065639, 0.56319068],
        [0.29972987, 0.51233415, 0.67346693, 0.15919373],
        [0.05047767, 0.33781589, 0.10806377, 0.17890281]],

       [[0.8858271 , 0.36536497, 0.21876935, 0.75249617],
        [0.10687958, 0.74460324, 0.46978529, 0.59825567],
        [0.14762019, 0.18403482, 0.64507213, 0.04862801]],

       [[0.24861251, 0.54240852, 0.22677334, 0.38141153],
        [0.92223279, 0.92535687, 0.56674992, 0.53347088],
        [0.01486002, 0.97789926, 0.5730289 , 0.791757  ]],

       [[0.56155736, 0.87733524, 0.58419583, 0.70884983],
        [0.14853345, 0.42845074, 0.69389007, 0.10461974],
        [0.43960524, 0.16620215, 0.50697863, 0.81903586]]])
np.random.seed(10)
np.random.randn(10)
array([ 1.3315865 ,  0.71527897, -1.54540029, -0.00838385,  0.62133597,
       -0.72008556,  0.26551159,  0.10854853,  0.00429143, -0.17460021])
nd = np.random.random_sample((2,3,4))
nd
array([[[0.92223279, 0.92535687, 0.56674992, 0.53347088],
        [0.01486002, 0.97789926, 0.5730289 , 0.791757  ],
        [0.56155736, 0.87733524, 0.58419583, 0.70884983]],

       [[0.14853345, 0.42845074, 0.69389007, 0.10461974],
        [0.43960524, 0.16620215, 0.50697863, 0.81903586],
        [0.09010673, 0.80006875, 0.56512635, 0.58934771]]])
np.random.random((10,3))
array([[0.19810066, 0.43611826, 0.29590376],
       [0.03755768, 0.03068484, 0.453105  ],
       [0.74486408, 0.55729541, 0.3851136 ],
       [0.1680728 , 0.83826132, 0.5990518 ],
       [0.78271482, 0.84850918, 0.60316298],
       [0.78106062, 0.61573688, 0.02116519],
       [0.75046461, 0.17604213, 0.45851421],
       [0.51312271, 0.48402089, 0.84438579],
       [0.17481389, 0.01463488, 0.84876407],
       [0.74267458, 0.45669754, 0.41689841]])

posted @ 2019-01-19 22:54  小猫妮  阅读(166)  评论(0编辑  收藏  举报