017/Python-Code
/1.1.1.py
import math
import numpy as np
import matplotlib.pyplot as plt
# 1.1.1
# 1. 生成1000个从0-1之间均匀分布的随机数,并保存在random数组中
# 2. 计算random数组中每个元素的平方根,并保存在sqrt_array数组中
# 3. 在一个图形中绘制random数组和sqrt_array数组对应的图形,其中random数组用蓝色填充,sqrt_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array = np.random.rand(1000)
sqrt_array = np.sqrt(random_array)
fig, ax = plt.subplots()
ax.fill(random_array, color="blue")
ax.plot(sqrt_array, color="red")
ax.set_title("Square root of random array")
ax.set_xlabel("Random array")
ax.set_ylabel("Square root of random array")
plt.show()
/1.2.1.py
import numpy as np
import matplotlib.pyplot as plt
# 1.2.1
# 1. 生成1000个从0-1之间均匀分布的随机数,并保存在random数组中
# 2. 计算random数组中每个元素的平方根,并保存在sqrt_array数组中
# 3. 在一个图形中绘制random数组和sqrt_array数组对应的图形,其中random数组用蓝色填充,sqrt_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array = np.random.rand(1000)
sqrt_array = np.sqrt(random_array)
fig, ax = plt.subplots()
ax.fill(random_array, color="blue")
ax.plot(sqrt_array, color="red")
ax.set_title("Square root of random array")
ax.set_xlabel("Random array")
ax.set_ylabel("Square root of random array")
plt.show()
/2.2.1.py
import numpy as np
import matplotlib.pyplot as plt
# 2.2.1
# 1. 生成1000个从0-1之间均匀分布的随机数,并保存在random数组中
# 2. 计算random数组中每个元素的平方根,并保存在sqrt_array数组中
# 3. 在一个图形中绘制random数组和sqrt_array数组对应的图形,其中random数组用蓝色填充,sqrt_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array = np.random.rand(1000)
sqrt_array = np.sqrt(random_array)
fig, ax = plt.subplots()
ax.fill(random_array, color="blue")
ax.plot(sqrt_array, color="red")
ax.set_title("Square root of random array")
ax.set_xlabel("Random array")
ax.set_ylabel("Square root of random array")
plt.show()
/3.1.1.py
import numpy as np
import matplotlib.pyplot as plt
# 3.1.1
# 1. 生成100个从1-10之间均匀分布的整数,并保存在random数组中
# 2. 计算random数组的累积和,并保存在cum_array数组中
# 3. 在一个图形中绘制random数组和cum_array数组对应的图形,其中random数组用蓝色填充,cum_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array = np.arange(1, 11)
cum_array = np.cumsum(random_array)
fig, ax = plt.subplots()
ax.fill(random_array, color="blue")
ax.plot(cum_array, color="red")
ax.set_title("Cumulative sum of random array")
ax.set_xlabel("Random array")
ax.set_ylabel("Cumulative sum of random array")
plt.show()
/1.1.2.py
import numpy as np
import matplotlib.pyplot as plt
# 1.1.2
# 1. 生成1000个从0-1之间均匀分布的随机数,并保存在random数组中
# 2. 计算random数组中每个元素的平方根,并保存在sqrt_array数组中
# 3. 在一个图形中绘制random数组和sqrt_array数组对应的图形,其中random数组用蓝色填充,sqrt_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array = np.random.rand(1000)
sqrt_array = np.sqrt(random_array)
fig, ax = plt.subplots()
ax.fill(random_array, color="blue")
ax.plot(sqrt_array, color="red")
ax.set_title("Square root of random array")
ax.set_xlabel("Random array")
ax.set_ylabel("Square root of random array")
plt.show()
/1.1.3.py
import numpy as np
import matplotlib.pyplot as plt
# 1.1.3
# 1. 生成1000个从0-1之间均匀分布的随机数,并保存在random数组中
# 2. 计算random数组中每个元素的平方根,并保存在sqrt_array数组中
# 3. 在一个图形中绘制random数组和sqrt_array数组对应的图形,其中random数组用蓝色填充,sqrt_array数组用红色的线画出
# 4. 在图形中添加标题和坐标轴标签
# 5. 显示图形
random_array =