大数据分析技术 习题答案项目三.docx
# coding: utf-8 import numpy as np1.创立一个从016的3*3矩阵Z = np. arange(16). reshape(4,4) print(Z)2.创立一个值从20到69的数组,步长为2Z = np. arange (20,69, 2) print(Z)3.生成一个6*6的对角矩阵Z = np. eye (6) print(Z)4.创立一个5*1()的随机值数组,并找到最大值,最小值,平均值,标准差。 Z = np. random, random(5, 10)Zmin, Zmax, Zmean, Zstd = Z. min(), Z. max (), Z. mean (), Z. std() print(Zmin, Zmax, Zmean, Zstd)5.创立一个四边为1,中间为0的二维数组,Z = np. ones (5, 5)1:-1 = 0print(Z)# 6.创立一个四边为0,中间为1的二维数组,Z = np. zeros (5, 5)Zl:-1, 1:-1 = 1 print(Z)7.如何计算(A+B)* (-A/2) ?A = np. ones(3)*lB = np.ones(3)*2C = np.ones(3)*3 np. add (A, B, out=B) np. divide (A, 2, out=A) np.negative(A, out=A) np.multiply(A, B, out=A)8.创立一个长度为5的数组,并做排序操作Z = np. random, random(5)Z. sort () print(Z)# 9.求数组a的累计和,累计积a = np. arange (2, 50, 2)print(np. cumsum(a)print(np. cumprod(a)# 10.创立随机数组,并保存该数组为numpy二进制文件读取numpy二进制文件Z = np. random, random(5)np. save('Z. npy', Z)c = np. load(* Z. npy')print (c)