先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新软件测试全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024b (备注软件测试)
正文
25 ,下面表达式结果为:
print(np.array(0)/np.array(0))
print(np.array(0)//np.array(0))
print(np.array([np.nan]).astype(int).astype(float))
nan
0
[-2.14748365e+09]
16,创建一个 5*5 矩阵值为1,2,3,4在对角线的下方
Z = np.diag(1+np.arange(4),k = -1)
print(Z)
[[0 0 0 0 0]
[1 0 0 0 0]
[0 2 0 0 0]
[0 0 3 0 0]
[0 0 0 4 0]]
26, 将一个 浮点数组从0舍入
Z = np.random.uniform(-10,+10,10)
print(Z)
print(np.copysign(np.ceil(np.abs(Z)),Z))
[-8.9433086 -1.94558017 5.09831429 0.75843992 -2.57004218 -3.68920573
-2.23238395 -6.75331705 3.62935401 -2.37852371]
[-9. -2. 6. 1. -3. -4. -3. -7. 4. -3.]
27,找到两个数组的共有元素;
Z1 = np.random.randint(0,10,10)
Z2 = np.random.randint(0,10,10)
print(np.intersect1d(Z1,Z2))
[0 1 4 6 7 8]
28,怎样返回昨天、今天、明天;
yes = np.datetime64(“today”) - np.timedelta64(1)
tod = np.datetime64(“today”)
tom = np.datetime64(“today”) + np.timedelta64(1)
print(yes)
print(tod)
print(tom)
2020-06-30
2020-07-01
2020-07-02
29,返回,19年2月份的所有日期
Z = np.arange(‘2019-02’,‘2019-03’,dtype = ‘datetime64[D]’)
print(Z)
[‘2019-02-01’ ‘2019-02-02’ ‘2019-02-03’ ‘2019-02-04’ ‘2019-02-05’
‘2019-02-06’ ‘2019-02-07’ ‘2019-02-08’ ‘2019-02-09’ ‘2019-02-10’
‘2019-02-11’ ‘2019-02-12’ ‘2019-02-13’ ‘2019-02-14’ ‘2019-02-15’
‘2019-02-16’ ‘2019-02-17’ ‘2019-02-18’ ‘2019-02-19’ ‘2019-02-20’
‘2019-02-21’ ‘2019-02-22’ ‘2019-02-23’ ‘2019-02-24’ ‘2019-02-25’
‘2019-02-26’ ‘2019-02-27’ ‘2019-02-28’]
30 ,怎样计算 ((A+B)*(-A/2))
A = np.ones(3)*1
B = np.ones(3)*2
C = np.ones(3) *3
np.add(A,B,out=A)
np.divide(A,2,out = -A)
np.negative(A,out =A)
np.multiply(A,B,out = A)
array([-6., -6., -6.])
31,取出随机数组的正数部分的整数部分
Z = np.random.uniform(0,10,10)
print(np.floor(Z))
[5. 8. 7. 7. 4. 4. 7. 7. 7. 1.]
32, 创见5*5 矩阵,行值为0-4;
Z = np.zeros((5,5))
Z += np.arange(5)
print(Z)
[[0. 1. 2. 3. 4.]
[0. 1. 2. 3. 4.]
[0. 1. 2. 3. 4.]
[0. 1. 2. 3. 4.]
[0. 1. 2. 3. 4.]]
33,构建一个生成函数生成10个整数,并转换为数组
def generate():
for x in range(10):
yield x
Z = np.fromiter(generate(),dtype =float,count = -1)
print(Z)Z = np.zeros((5,5))
Z += np.arange(5)
print(Z)
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
34 ,创建一个10个元素大小的数组,值为0-1
Z = np.linspace(0,1,11,endpoint = False)[1:]
Z
array([0.09090909, 0.18181818, 0.27272727, 0.36363636, 0.45454545,
0.54545455, 0.63636364, 0.72727273, 0.81818182, 0.90909091])
35,判断两个随机数组,是否相等;
A = np.random.randint(0,2,5)
B = np.random.randint(0,2,5)
equal = np.array_equal(A,B)
print(equal)
False
37,10*2 的随机矩阵,由笛卡尔坐标转化为极坐标
Z = np.random.random((10,2))
X,Y = Z[:,1],Z[:,1]
R = np.sqrt(X**2+Y**2)
T = np.arctan2(Y,X)
print®
print(T)
[0.12396673 1.09640358 0.60171085 0.93054782 0.05433122 0.88863367
0.10389402 0.45757275 0.53011318 0.17896545]
[0.78539816 0.78539816 0.78539816 0.78539816 0.78539816 0.78539816
0.78539816 0.78539816 0.78539816 0.78539816]
38, 创建一个10大小的随机向量,把最大值取为0
Z = np.random.random(10)
Z[Z.argmax()] = 0
Z
array([0.49363055, 0.03622898, 0.19958785, 0.1625108 , 0. ,
0.88062849, 0.27145883, 0.42484903, 0.62000329, 0.41577207])
39,给两个数据组,构造为 柯西矩阵(CIJ = 1/(xi-yj))
X = np.arange(8)
Y = X+0.5
C = 1.0/np.subtract.outer(X,Y)
print(np.linalg.det©)
3638.1636371179666
40,在一个一维数组中找到与给定值最近的值
Z = np.arange(100)
v = np.random.uniform(0,100)
print(v)
index = (np.abs(Z-v)).argmin()
print(Z[index])
14.763688219125658
15
玩转 Numpy 的精选习题 (三)
推送的 20 道题目是比较难的,里面会用到一些不常用的函数,例如 np.bincount()、np.atleast_2d()、np.genfromtxt(),但仔细琢磨的话问题都不大
这 20 道解题步骤中虽然大部分都是一些常见函数,但用的是都是一些进阶语法,有时解一道题需要多个函数混合在一起使用,需要仔细思考它的用法
41,打印一个数组中所有值
np.set_printoptions(threshold =float(‘inf’))
Z = np.zeros((16,16))
print(Z)
//
42,给定一个标量,在一个向量中找到值最近的元素值
42,在向量元素中找离指定元素最近的值:
Z = np.arange(100)
v = np.random.uniform(0,100)
index = (np.abs(Z-v)).argmin()
print(Z[index])
15
43,建立一个结构数组,来表示一个坐标和 RGB 编码
Z =np.zeros(10,
[(‘position’,[(‘x’,float,1),
(‘y’,float,1)]),
(‘color’,[(‘r’,float,1),
(‘g’,float,1),
(‘b’,float,1)])])
print(Z)
[((0., 0.), (0., 0., 0.)) ((0., 0.), (0., 0., 0.))
((0., 0.), (0., 0., 0.)) ((0., 0.), (0., 0., 0.))
((0., 0.), (0., 0., 0.)) ((0., 0.), (0., 0., 0.))
((0., 0.), (0., 0., 0.)) ((0., 0.), (0., 0., 0.))
((0., 0.), (0., 0., 0.)) ((0., 0.), (0., 0., 0.))]
44,指定一个100*2的向量矩阵,代表点的坐标,计算矩阵中点到点之间的距离
Z = np.random.random((10,2))
X,Y = np.atleast_2d(Z[:,0],Z[:,1])
D = np.sqrt((X-X.T)**2+(Y-Y.T)**2)
D
array([[0. , 0.98633439, 0.72167275, 0.90188932, 0.13230666,
0.74692975, 0.06223381, 0.60174661, 0.95391954, 0.92008742],
[0.98633439, 0. , 0.77985879, 0.1631969 , 0.90583532,
0.30879931, 0.92419607, 0.39486349, 1.00587334, 1.0537349 ],
[0.72167275, 0.77985879, 0. , 0.61879559, 0.7580086 ,
0.48464973, 0.68199994, 0.65207576, 0.28058449, 0.2957362 ],
[0.90188932, 0.1631969 , 0.61879559, 0. , 0.83909907,
0.1681398 , 0.83995416, 0.35751067, 0.84286462, 0.89058005],
[0.13230666, 0.90583532, 0.7580086 , 0.83909907, 0. ,
0.69570875, 0.10653016, 0.51251781, 1.01061853, 0.98608667],
[0.74692975, 0.30879931, 0.48464973, 0.1681398 , 0.69570875,
0. , 0.68572148, 0.27153623, 0.73491355, 0.77182869],
[0.06223381, 0.92419607, 0.68199994, 0.83995416, 0.10653016,
0.68572148, 0. , 0.54051085, 0.9237499 , 0.89448777],
[0.60174661, 0.39486349, 0.65207576, 0.35751067, 0.51251781,
0.27153623, 0.54051085, 0. , 0.9285785 , 0.94720901],
[0.95391954, 1.00587334, 0.28058449, 0.84286462, 1.01061853,
0.73491355, 0.9237499 , 0.9285785 , 0. , 0.08212287],
[0.92008742, 1.0537349 , 0.2957362 , 0.89058005, 0.98608667,
0.77182869, 0.89448777, 0.94720901, 0.08212287, 0. ]])
45,将 float32 转化为 int 32
Z = (np.random.rand(10)*100).astype(np.float32)
Y = Z.view(np.int32)
Y[:] = Z
Y
[ 3 71 47 23 57 54 67 1 76 6]
46,读取下面文本并转化为二维 array
from io import StringIO
s = StringIO(‘’‘1, 2, 3, 4, 5
6, , , 7, 8
, , 9,10,11’‘’)
Z =np.genfromtxt(s,delimiter = “,”,dtype = np.int)
print(Z)
[[ 1 2 3 4 5]
[ 6 -1 -1 7 8]
[-1 -1 9 10 11]]
47,Numpy 中数组枚举的表示方法
Z = np.arange(9).reshape(3,3)
for index,value in np.ndenumerate(Z):
print(index,value)
for index in np.ndindex(Z.shape):
print(index,Z[index])
48,建立一个二维高斯数组
X,Y = np.meshgrid(np.linspace(-1,1,10),np.linspace(-1,1,10))
D = np.sqrt(X*X+Y*Y)
sigma,mu = 1.0,0.0
G = np.exp(-((D-mu)**2/(2.0*sigma**2)))
print(G)
[[0.36787944 0.44822088 0.51979489 0.57375342 0.60279818 0.60279818
0.57375342 0.51979489 0.44822088 0.36787944]
[0.44822088 0.54610814 0.63331324 0.69905581 0.73444367 0.73444367
0.69905581 0.63331324 0.54610814 0.44822088]
[0.51979489 0.63331324 0.73444367 0.81068432 0.85172308 0.85172308
0.81068432 0.73444367 0.63331324 0.51979489]
[0.57375342 0.69905581 0.81068432 0.89483932 0.9401382 0.9401382
0.89483932 0.81068432 0.69905581 0.57375342]
[0.60279818 0.73444367 0.85172308 0.9401382 0.98773022 0.98773022
0.9401382 0.85172308 0.73444367 0.60279818]
[0.60279818 0.73444367 0.85172308 0.9401382 0.98773022 0.98773022
0.9401382 0.85172308 0.73444367 0.60279818]
[0.57375342 0.69905581 0.81068432 0.89483932 0.9401382 0.9401382
0.89483932 0.81068432 0.69905581 0.57375342]
[0.51979489 0.63331324 0.73444367 0.81068432 0.85172308 0.85172308
0.81068432 0.73444367 0.63331324 0.51979489]
[0.44822088 0.54610814 0.63331324 0.69905581 0.73444367 0.73444367
0.69905581 0.63331324 0.54610814 0.44822088]
[0.36787944 0.44822088 0.51979489 0.57375342 0.60279818 0.60279818
0.57375342 0.51979489 0.44822088 0.36787944]]
49,在二维数组中随机放置 p 个元素
n = 10
p = 3
Z = np.zeros((n,n))
np.put(Z,np.random.choice(range(n*n),p,replace = False),1)
print(Z)
[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
[0. 0. 0. 1. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
50,矩阵减去每一行的平均值
X = np.random.rand(5,10)
Y = X - X.mean(axis =1,keepdims = True)
#Y = X -X.mean(axis=1).reshape(-1,1)
print(Y)
[[-0.2854325 0.20882031 0.35568196 0.18316993 -0.40776416 -0.30312722
0.07405133 0.35347259 -0.09991147 -0.07896078]
[ 0.04400539 -0.12949299 0.43078155 0.10710735 0.35645354 -0.43201896
0.1102518 -0.11709654 0.01395583 -0.38394697]
[-0.07116609 -0.09382485 0.02956884 -0.29241189 -0.05337575 -0.24354029
0.28228751 0.28369777 -0.22918485 0.3879496 ]
[ 0.34436033 0.29003034 -0.21067108 -0.09945774 0.0428871 -0.17125693
-0.28001421 0.40165161 -0.03741505 -0.28011437]
[ 0.32963488 -0.03061654 -0.36657671 -0.05771164 -0.35016734 0.27941279
0.19521001 0.44803322 -0.31404906 -0.13316961]]
51,以某一列对整个数组的行进行排序
Z = np.random.randint(0,10,(3,3))
print(Z[Z[:,1].argsort()])
[[3 4 8]
[1 5 2]
[2 8 2]]
52,判断一个2D数组,是否含有空列
Z = np.random.randint(0,3,(3,10))
print((~Z.any(axis = 0)).any())
True
53,在数组中找到给定值的最近值
Z = np.random.uniform(0,1,10)
z = 0.5
m = Z.flat[np.abs(Z-z).argmin()]
print(m)
0.507763391604458
54,给定两个二维数组维度分别为 13,31;利用迭代器计算他们的和
A = np.arange(3).reshape(3,1)
B = np.arange(3).reshape(1,3)
it = np.nditer([A,B,None])
for x,y,z in it:z[…] = x+y
print(it.operands[2])
[[0 1 2]
[1 2 3]
[2 3 4]]
55,基于索引列表 I ,对应权重 X,进行加权计算得到F
需要注意一下,这里用到 np.bincount() 函数,只有一个参数时,返回一个数组表示每个元素出现的次数;如果设置两个参数则会涉及到加权运算,理解方面比较困难,建议查阅一下官方文档
X = [1,2,3,4,5,6]
I = [1,3,9,3,4,1]
F = np.bincount(I,X)
print(F)
[0. 7. 0. 6. 5. 0. 0. 0. 0. 3.]
56,给定一个 图片像素数组(w,h,3),计算其中唯一颜色数量
w,h = 16,16
I = np.random.randint(0,2,(h,w,3)).astype(np.ubyte)
F = I[…,0]*256*256 + I[…,1]*256 + I[…,2] # color RGB 进行编码
n = len(np.unique(F))
print(n)
4
57,给定一个四维数组,同时计算最后轴元素之和
A = np.random.randint(0,10,(3,4,3,4))
sum = A.sum(axis = (-2,-1))# 计算最后两列;
print(sum)
second solutions
sum = A.reshape(A.shape[:-2]+(-1,)).sum(axis = -1)
[[62 59 48 61]
[53 59 45 48]
[50 56 71 60]]
58,给定一维数组D,通过相同维度向量 S ,通过自己索引来计算子集D 的平均值
D = np.random.uniform(0,1,100)
S = np.random.randint(0,10,100)
D_sums = np.bincount(S,weights =D)
D_counts = np.bincount(S)
D_means = D_sums/D_counts
print(D_means)
[0.50247673 0.43057174 0.54440853 0.60862306 0.61939138 0.6184843
0.57271125 0.49704534 0.52671729 0.4849897 ]
59,计算一个点积的对角线
A = np.random.uniform(0,1,(5,5))
B = np.random.uniform(0,1,(5,5))
np.diag(np.dot(A,B))
Second solutions
np.sum(A*B.T,axis = 1)
array([0.49721784, 1.06865483, 0.65669748, 0.78147516, 1.11704931])
60,给定一维向量例如[1,2,3,4,5],在相邻两个值之间加入3个0
Z = np.array([1,2,3,4,5])
nz = 3
Z0 = np.zeros(len(Z)+(len(Z)-1)*(nz))
Z0[::nz+1] = Z
print(Z0)
[1. 0. 0. 0. 2. 0. 0. 0. 3. 0. 0. 0. 4. 0. 0. 0. 5.]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注软件测试)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
(0,1,(5,5))
B = np.random.uniform(0,1,(5,5))
np.diag(np.dot(A,B))
Second solutions
np.sum(A*B.T,axis = 1)
array([0.49721784, 1.06865483, 0.65669748, 0.78147516, 1.11704931])
60,给定一维向量例如[1,2,3,4,5],在相邻两个值之间加入3个0
Z = np.array([1,2,3,4,5])
nz = 3
Z0 = np.zeros(len(Z)+(len(Z)-1)*(nz))
Z0[::nz+1] = Z
print(Z0)
[1. 0. 0. 0. 2. 0. 0. 0. 3. 0. 0. 0. 4. 0. 0. 0. 5.]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024b (备注软件测试)
[外链图片转存中…(img-ci6Mt227-1713586656069)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!