Week 3 · Read arrays and explain them with plots

English translation

Before practice

01 How to organize data

Several items were measured for multiple people. How should these values be organized to make the required computations and comparisons easier?

Description
  • Giving value positions consistent meanings, such as placing the same item in the same column, makes selection, computation, and comparison easier.
  • Define what rows and columns mean, as well as the array size.

02 Ways to examine data

What representation would help reveal changes or differences in many measurements more effectively than reading numbers alone?

Description
  • Table: inspect specific values / Plot: compare trends and changes
  • Include axis names, units, and legends needed to interpret plots

Practice

1. Array shapes

  1. Create a NumPy Array from score=[728590689588]\mathrm{score}=\begin{bmatrix}72&85&90&68&95&88\end{bmatrix} and print its shape, dtype, mean, values at least 80, and their count.
  2. Arrange 1~20 into (4,5), then print the first row, last column, middle 2-row×3-column region, and even values separately.

2. Operations and verification

  1. For A=[2.01.01.03.0]A=\begin{bmatrix}2.0&1.0\\1.0&3.0\end{bmatrix} and B=[1.00.02.01.0]B=\begin{bmatrix}1.0&0.0\\2.0&1.0\end{bmatrix}, compute the Element-wise Product and Matrix Multiplication and explain how element (0,1) is obtained.
  2. Compute A's Determinant and Inverse and use np.allclose to verify that A@Inverse is the Identity.
  3. Change A[0,0] to 4 and repeat.

3. Plot the results

  1. Create x with 100 samples from 0~2π and plot sin and cos together.
  2. Then use epoch=[12345]\mathrm{epoch}=\begin{bmatrix}1&2&3&4&5\end{bmatrix}, loss=[1.81.20.90.70.6]\mathrm{loss}=\begin{bmatrix}1.8&1.2&0.9&0.7&0.6\end{bmatrix}, and accuracy=[0.40.60.70.750.78]\mathrm{accuracy}=\begin{bmatrix}0.4&0.6&0.7&0.75&0.78\end{bmatrix} to display sin, cos, Loss, and Accuracy in a 2×2 Figure.
  3. Label axes and add a Legend, locate the maximum Accuracy in code, and mark it with an annotation.

Submission and saving

Include code, actual outputs and plots, and your own interpretation. Submit through KLAS; check the semester schedule and latest announcements for the deadline.

Filename: Name_StudentID_Week3.ipynb.

Restart the runtime, run all code from the top, then save.

Optional practice

reshape with an incompatible element count

  1. After importing NumPy, add a Code Cell at the bottom of the notebook and run the following code.
    debug_values = np.arange(12)
    for debug_shape in [(5, 3), (3, 4)]:
        print("requested shape:", debug_shape, "elements:", debug_values.size)
        try:
            print(debug_values.reshape(debug_shape))
        except ValueError as error:
            print(type(error).__name__, str(error))
  2. In a Text Cell, tabulate the required element count and execution success for each requested shape. Also explain in one sentence the order in which values from 0 to 11 are arranged in the successful array.