import numpy as np#生成三行两列的从0到1的元素是随机数的矩阵simple1 = np.random.random((3,2))print(simple1)[[0.02619904 0.49869176][0.00253581 0.32766397][0.28004011 0.44864681]]#numpy.random.normal(loc=0,scale=1e-2,size=shape)#其参数意义为:#参数loc(float):正态分布的均值,对应着这个分布的中心。loc=0说明这一个以Y轴为对称轴的正态分布,#参数scale(float):正态分布的标准差,对应分布的宽度,scale越大,正态分布的曲线越矮胖,scale越小,曲线越高瘦。#参数size(int 或者整数元组):为生成的数组的形状#生成三行两列的元素符合标准正态分布的是随机数的矩阵simple2 = np.random.normal(size = (3,2))print(simple2)[[ 0.36900889 0.21500554][ 0.77479755 0.36790392][-2.73268657 -0.22726543]]#生成三行两列的元素是随机整数的矩阵simple3 = np.random.randint(0,10,size = (3,2))print(simple3)[[2 1][9 6][3 4]]#计算矩阵中所有元素的总和print(np.sum(simple1))1.583777502266864#提取矩阵中最小的元素print(np.min(simple1))0.002535810048106102#提取矩阵中最大的元素print(np.max(simple1))0.49869175688273426#对矩阵的列进行求和print(np.sum(simple1,axis = 0))[0.30877496 1.27500254]#对矩阵的行进行求和print(np.sum(simple1,axis = 1))[0.5248908 0.33019978 0.72868693]#计算矩阵中最小元素的索引print(np.argmin(simple1))2#计算矩阵中最大元素的索引print(np.argmax(simple1))1#计算矩阵中所有元素的平均值print(np.mean(simple1))0.26396291704447733print(simple1.mean())0.26396291704447733#计算矩阵中所有元素的中位数print(np.median(simple1))0.303852040723694#计算矩阵中每个元素开方的结果print(np.sqrt(simple1))[[0.16186117 0.70618111][0.05035683 0.5724194 ][0.52918817 0.66981103]]simple4 = np.random.randint(0,10,size = (1,10))print(simple4)[[5 2 1 9 7 8 2 6 8 3]]#对只有一行的矩阵中的元素进行排序print(np.sort(simple4))[[1 2 2 3 5 6 7 8 8 9]]#对应多行元素的矩阵进行排序的结果是对每一行的元素进行排序print(np.sort(simple1))[[0.02619904 0.49869176][0.00253581 0.32766397][0.28004011 0.44864681]]#小于2就变为2,大于7就变成7print(np.clip(simple4,2,7))[[5 2 2 7 7 7 2 6 7 3]]#生成100个服从[0,1)均匀分布的数组print(np.random.rand(100))[0.02655411 0.64600619 0.06270094 0.35745073 0.13310318 0.782864930.44741411 0.17085896 0.95124193 0.21309685 0.47686385 0.998868380.67326801 0.02366001 0.5388905 0.60126232 0.52413128 0.558590290.74207128 0.60914129 0.20589901 0.18753216 0.99010108 0.502206890.20721585 0.57084253 0.64306379 0.87261796 0.33480705 0.114817770.37030914 0.0018776 0.06591107 0.59238653 0.2974 0.982393990.35755203 0.36263331 0.37949681 0.35566217 0.27898376 0.22364260.36995981 0.21522713 0.61280523 0.65221438 0.13609006 0.35153630.87931669 0.00815837 0.18648032 0.18146687 0.59842835 0.25695840.12938341 0.54186809 0.1827327 0.5684 0.42860094 0.976354940.40242773 0.80681818 0.76369634 0.65686934 0.57744499 0.387602370.62788257 0.1195395 0.77069706 0.6610301 0.4556943 0.555550470.0555818 0.52473909 0.55553662 0.09958023 0.93970248 0.30077240.32284174 0.29472103 0.57330981 0.11677637 0.84424229 0.876289550.51104388 0.37309788 0.96692533 0.54701478 0.32077409 0.502728140.86230671 0.16055657 0.07061821 0.78766101 0.54857954 0.190009560.47035823 0.769983 0.2113017 0.09091019]#生成的数组只有一个数print(np.random.rand())0.9333659910325818