1.导入numpy库并简写为np
1.18.5
2.打印numpy的版本和配置说明
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
3.创建一个长度为10的空向量
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
4.如何找到任何一个数组的内存大小
800
5.如何从命令行得到numpy中add函数的说明文档?
6.创建一个长度为10并且除了第五个值为1的空向量
[0., 0., 0., 0., 1., 0., 0., 0., 0., 0.]
7.创建一个值域范围从10到49的向量
[10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49]
8.反转一个向量(第一个元素变为最后一个)
[49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0]
9.创建一个3x3并且值从0到8的矩阵
[[0 1 2]
[3 4 5]
[6 7 8]]
10.找到数组[1,2,0,0,4,0]中非0元素的位置索引
(array([0, 1, 4]),)
11.创建一个3x3的单位矩阵
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
12.创建一个3x3x3的随机数组
[[[0.49636271 0.83838843 0.06417393]
[0.82195645 0.51237583 0.0114491 ]
[0.7405036 0.39659706 0.03227348]]
[[0.63851754 0.80021438 0.7920785 ]
[0.2406759 0.67543697 0.42027336]
[0.63085702 0.35717684 0.97860962]]
[[0.01086027 0.74921743 0.26180766]
[0.86373045 0.89711615 0.69148172]
[0.40816789 0.57048578 0.27933363]]]
13.创建一个10x10的随机数组并找到它的最大值和最小值
[[0.75663674 0.17844001 0.85002126 0.13172174 0.29408908 0.41969569
0.23361479 0.2108635 0.20592198 0.27844824]
[0.81355517 0.41224512 0.11997801 0.96950686 0.92275456 0.3488865
0.75720993 0.74558365 0.975169 0.60246761]
[0.22106176 0.09018057 0.7895037 0.36480635 0.09659013 0.67309123
0.46910627 0.1764413 0.84397167 0.74586522]
[0.57137615 0.31583 0.88894133 0.70353074 0.39971682 0.91511001
0.76765151 0.5745941 0.77788015 0.79931621]
[0.03478835 0.41559061 0.71280684 0.16909797 0.46635441 0.8827292
0.65676973 0.66978226 0.00355154 0.53219789]
[0.88288346 0.17108551 0.57297318 0.87288666 0.06630736 0.06485355
0.24679334 0.27741585 0.08302555 0.75426484]
[0.36280452 0.64841807 0.97838234 0.88603573 0.1671354 0.59336731
0.38955173 0.34285529 0.7836714 0.90464085]
[0.90640051 0.74722665 0.38180324 0.43325245 0.0741859 0.5579621
0.81968112 0.14065454 0.05105436 0.69727726]
[0.54015284 0.73357179 0.57264243 0.96944606 0.48120064 0.52303426
0.72974627 0.15313958 0.98512348 0.41098146]
[0.58610653 0.68952747 0.05254411 0.87168296 0.14973974 0.73087013
0.95045341 0.00521367 0.26853988 0.36178675]]
0.0035515374660728405 0.9851234802087657
14.创建一个长度为30的随机向量并找到它的平均值
[0.25621257 0.21803699 0.15008757 0.52329855 0.63721352 0.82697183
0.88605523 0.56303141 0.76514747 0.10767787 0.46170384 0.3991193
0.60063211 0.31583176 0.44926071 0.70317634 0.18852366 0.44927385
0.96359451 0.54583082 0.57153248 0.21319883 0.17595709 0.14272109
0.24723186 0.42819483 0.99494263 0.83336304 0.74526906 0.38350683]
0.491553254982445
15.创建一个二维数组,其中边界值为1,其余值为0
[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 0. 0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 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. 1. 1. 1. 1. 0. 0. 0. 0.]
[0. 0. 0. 1. 1. 1. 1. 1. 0. 0. 0. 0.]
[0. 0. 0. 1. 1. 1. 1. 1. 0. 0. 0. 0.]
[0. 0. 0. 1. 1. 1. 1. 1. 0. 0. 0. 0.]
[0. 0. 0. 1. 1. 1. 1. 1. 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.]]
17.以下表达式运行结果是什么
nan
False
nan
False
0.3 0.30000000000000004
18.创建一个5x5的矩阵,并设置值1,2,3,4落在其对角线下方位置
d: [1 2 3 4]
[[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]]
19.创建一个8x8的矩阵,并且设置成棋盘样式
[[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]]
20.考虑一个(6,7,8)形状的数组,其第100个元素的索引(x,y,z)是什么
(1, 5, 4)
转换后的数据为:
[[ 2 3 4 5]
[ 6 7 8 1]
[12 23 34 55]]
转换后的索引为: (1, 3)
此索引的值为: 1
21.用tile函数去创建一个8X8的棋盘样式矩阵
[[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]]
22.对一个 5x5 的随机矩阵做归一化
[[0.60869233 0.9835157 0.21854819 1. 0.83353816]
[0. 0.68240932 0.45124496 0.88266605 0.31929441]
[0.16032999 0.81138498 0.91282807 0.4355519 0.41880903]
[0.56181584 0.60601155 0.9521618 0.79943604 0.96619814]
[0.01959091 0.80151255 0.916702 0.56048952 0.46647695]]
23.创建一个将颜色描述为(RGBA)四个无符号字节的自定义dtype
[('r', 'u1', (1,)), ('g', 'u1', (1,)), ('b', 'u1', (1,)), ('a', 'u1', (1,))]
24.一个5x3与一个3x2的矩阵相乘,矩阵乘积是什么
[[3. 3.]
[3. 3.]
[3. 3.]
[3. 3.]
[3. 3.]]
25.给定一个一维数组,对其在3到8之间的所有元素取反
[ 0 1 2 3 -4 -5 -6 -7 -8 9]
[ 0 1 2 3 -4 -5 -6 -7 -8 9]