Hosted by CoCalc
Download
Kernel: Python 3 (system-wide)
print('this is the second homework of MIP2023.')
this is the second homework of MIP2023.
#This is a project creating 10 random numbers to an array and turning it into a figure. import numpy as np import matplotlib.pyplot as plt rand_arr = np.random.randint(0, 10, 100) print(rand_arr) print('\n') plt.figure(figsize=(8, 4)) plt.plot(rand_arr) plt.title('hw02_Haoqi Zhang 202100800750') # The eventual figure is disable to show Chinese, thus using name in English. plt.xlabel('random number') plt.ylabel('Index') rand_mat = rand_arr.reshape((10, 10)) print(rand_mat) print('\n') fig, ax = plt.subplots(figsize=(4, 4)) im = ax.matshow(rand_mat, cmap='jet') fig.colorbar(im) ax.set_title('hw02_Haoqi Zhang 202100800750') for i in range(rand_mat.shape[0]): for j in range(rand_mat.shape[1]): if rand_mat[i, j] > 5: rand_mat[i, j] = 1 else: rand_mat[i, j] = 0 print(rand_mat) print('\n') fig, ax = plt.subplots(figsize=(4, 4)) im_2 = ax.matshow(rand_mat) fig.colorbar(im_2) ax.set_title('hw02_Haoqi Zhang 202100800750')
[6 7 7 8 4 4 8 7 8 8 8 6 8 1 8 2 2 2 0 6 8 7 9 4 4 9 1 2 2 7 4 9 5 3 5 0 3 0 0 9 2 0 2 1 3 5 9 5 1 9 8 1 5 2 0 3 5 6 2 7 3 0 9 1 9 3 3 6 2 7 3 5 9 2 4 7 7 8 7 2 2 5 6 2 8 5 8 6 0 2 0 4 8 7 5 5 1 7 7 2] [[6 7 7 8 4 4 8 7 8 8] [8 6 8 1 8 2 2 2 0 6] [8 7 9 4 4 9 1 2 2 7] [4 9 5 3 5 0 3 0 0 9] [2 0 2 1 3 5 9 5 1 9] [8 1 5 2 0 3 5 6 2 7] [3 0 9 1 9 3 3 6 2 7] [3 5 9 2 4 7 7 8 7 2] [2 5 6 2 8 5 8 6 0 2] [0 4 8 7 5 5 1 7 7 2]] [[1 1 1 1 0 0 1 1 1 1] [1 1 1 0 1 0 0 0 0 1] [1 1 1 0 0 1 0 0 0 1] [0 1 0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0 0 1] [1 0 0 0 0 0 0 1 0 1] [0 0 1 0 1 0 0 1 0 1] [0 0 1 0 0 1 1 1 1 0] [0 0 1 0 1 0 1 1 0 0] [0 0 1 1 0 0 0 1 1 0]]
Text(0.5, 1.0, 'hw02_Haoqi Zhang 202100800750')
Image in a Jupyter notebookImage in a Jupyter notebookImage in a Jupyter notebook