---
# System prepended metadata

title: 20210514 - Python Homwork - Application 2
tags: [python2021]

---

# 20210514 - Python Homwork - Application 2
###### tags: `python2021`

* 要求 (request)：
    * 格式請依照hwA2的標準 (檔名:hwA2-1.py, hwA2-2.py...，最後將所有檔案壓縮至"學號_hwA2.zip"上傳e3)
    * 輸出檔案內容以TA截圖為標準

---
# Question 1: Basic ndarray Operation
**`hwA2-1_temp.py`** is an unfinished file for expressing features of an ndarray `encrypt`, which is read from **`encrypt.npy`**. In this question, you need to print out features of `encrypt`, including **size**, **shape**, **number of dimensions**, and **data type of this ndarray**. Then reshape the ndarray to **900 x 1200** and named it as `decrypt`. A decrypted ndarray will be generated and can be converted to a classic meme figure with second half of the codes.

---
# Question 2: Trigonometric Function Integral
Please calculate<center>![](https://i.imgur.com/rTLB6yU.png)
</center>

with functions of **np.arange()** or **np.linspace()** to generate an arithmetic progression (等差級數) from `-3 to 2π`, and common difference(公差) with `0.001`. Finally, round the number of answer to 5th place after decimal point. (化簡到小數點後第五位)

---
# Question 3: Lotto 539 (今彩539)
Lotto 539 (今彩539) is a lottery game which is popular in Taiwan. In this game, you need to pick 5 numbers from 1 to 39. A lottery machine will draw 5 numbers (中獎號碼) **randomly** every time and indicate whether you win an award or not. There are 4 kinds of awards in Lotto 539 (今彩539), which is shown as below:<center>![](https://i.imgur.com/gnSRbf9.png)
</center>

And the amount of each prizes are as follows <center>![](https://i.imgur.com/pNHrAHZ.png)
</center>

Please write a program which imitates a lottery machine and calculate how much money you can get if you have a lottery ticket with the following number set:
>## `[1,13,16,23,37]`
:::warning
**Warning:** You need to pay attention about the boundary of numbers and turn off the repeatability with some functions in NumPy!!
:::


---
# Question 4: Design a Matrix Multiplication Calculator
Please write a program to calculate the multiplication of two matrices. The execution processes of the program are shown as below:

:::info
1. Input sizes of row and column of the two matrices in order.
2. Judge whether the sizes of the two matrices are available for matrix multiplication.
3. Input the values in the Matrix 1 in order, the state of Matrix 1 will print out followed by every input.
4. If the field of Matrix 1 has not been inputed, please display "nan" in that field.
5. Repeat the steps of 3~4 in Matrix 2.
6. Print out the result of two matrices.
:::

### ***Example 4-1:***
![](https://i.imgur.com/5J7GKjL.png)

### ***Example 4-2:***
![](https://i.imgur.com/LeTUJVR.png)

---
# Question 5: Calculate the Determine & Inverse Matrix of a 2x2 Matrix
For a 2x2 Matrix A
![](https://i.imgur.com/Lpq6iT8.png)

The inverse matrix is
![](https://i.imgur.com/txaLDRx.png)

Where determine A is
![](https://i.imgur.com/GUTPMPR.png)

Please write a program to calculate the determine and the inverse matrix of an input matrix A. If value of the determine is 0, then the inverse matrix will not exist. The examples are shown as below.

:::warning
**Warning:** You cannot use the function of **np.linalg.inv()** and **np.linalg.det()** in this program!
:::

### ***Example 5-1:***
![](https://i.imgur.com/POnkLqq.png)

### ***Example 5-2:***
![](https://i.imgur.com/HFiacMe.png)

### ***Example 5-3:***
![](https://i.imgur.com/H2X6bmH.png)