- Printing the List of Odd Numbers: Finally, after iterating through the entire array `A`, the `odd_arrays` list contains all the odd numbers extracted from the array.. - terate Through
Trang 1FACULTY OF INFORMATION TECHNOLOGY
PHAN HUY PHAT – 523H0073
DUONG TRAN QUOC KHANH – 523H0040
INFORMATION TECHNOLOGY
MIDTERM ESSAY
SOFTWARE ENGINEERING
HO CHI MINH CITY, 2024
Trang 2FACULTY OF INFORMATION TECHNOLOGY
PHAN HUY PHAT – 523H0073
DUONG TRAN QUOC KHANH – 523H0040
INFORMATION TECHNOLOGY
MIDTERM ESSAY
Advised by PhD Huynh Thi Thu Thuy
HO CHI MINH CITY, 2024
Trang 3OUR THANK
We would like to sincerely express our gratitude to Ton Duc Thang University, the Facutly of Information Technology, and especially to Master Huynh Thi Thu Thuy We are thankful to all the esteemed professors and lecturers in general, and Ms Thuy in particular, for their enthusiastic guidance and support Their instruction and assistance have significantly enriched our knowledge and greatly improved the completion of this report We assure that this report is the result
of our learning and self-study, our work and personal effort under the guidance of
Ms Huynh Thi Thu Thuy, and we take full responsibility for all the information and opinions presented in this report
Ho Chi Minh city, 7th April 2024
Author (Signature and full name)
Phat Khanh Phan Huy Phat Duong Tran Quoc Khanh
Trang 4DECLARATION OF AUTHORSHIP
I hereby affirm that this is my own research work and has been conducted under the scientific guidance of PhD.Huynh Thi Thu Thuy The research contents and results presented in this topic are honest and have not been published in any form previously The data in the tables used for analysis, comments, and evaluation have been collected by the author from various sources, which are clearly referenced in the bibliography section
Furthermmore, the project also includes some observations, evaluations, and data from other authors and organizations, all of which are duly cited and referenced
Should there be any detection of fraud, i fully accept responsibility for the content of my project Ton Duc Thang University is not associated with any
copyright or intellectual property violations that may arise from my actions during the project (if any)
Ho Chi Minh city, 7th April 2024
Author (Signature and full name)
Phat
Phan Huy Phat
Khanh
Duong Tran Quoc Khanh
Trang 5TABLE OF CONTENT
CHAPTER 1 METHODOLOGY OF SOLVING TASKS 2
1.1 Question 1d: 2
CHAPTER 2 DESIGNING AND IMPLEMENTING 7
2.1 Content 1 7
2.2 Content 2 7
CHAPTER 3 RESULT 8
3.1 Content 1 8
3.2 Content 2 8
CHAPTER 4 CONCLUSION 10
4.1 Conclusion 10
4.2 Potential and Development Direction 10
REFERENCES 11
Trang 6CHAPTER 1 METHODOLOGY OF SOLVING TASKS
1.1 Methodology of solving task 1d:
- Initializing an Empty List: Firstly, we initialize an empty list called
`odd_arrays` This list will be used to store odd numbers extracted from the array `A`
- Iterating Through Rows and Columns of the Array: Using two nested loops, we iterate through each element of the array `A` using row and column indices
- Checking for Odd Numbers: At each position `(i, j)` in the array `A`, we check whether the value of the element is odd by checking the remainder when divided by 2 If the remainder is not zero, it indicates that the number is odd, and we append it to the `odd_arrays` list
- Storing Odd Numbers: The odd numbers found are appended to the
`odd_arrays` list using the `append()` method
- Printing the List of Odd Numbers: Finally, after iterating through the entire array `A`, the `odd_arrays` list contains all the odd numbers extracted from the array The code prints this list to display the result to the user
1.2 Methodology of solving task 1e:
- Define a Function to Check Prime Numbers (`is_prime`):
The function `is_prime(num)` is defined to determine whether a given number `num` is prime
It first checks if `num` is less than or equal to 1, in which case it returns
`False` because prime numbers must be greater than 1
Then, it iterates through numbers from 2 to the square root of `num` (inclusive) using a `for` loop
Trang 7 Within the loop, if `num` is divisible by any of these numbers, it means `num` is not prime, and the function returns `False`
If the loop completes without finding any divisors, the function returns
`True`, indicating that `num` is a prime number
- Initialize an Empty List for Prime Numbers (`prime_numbers`):
An empty list called `prime_numbers` is initialized This list will store all prime numbers found in the array `A`
- terate Through Flattened Array Elements:
Using a `for` loop, the code iterates through each element of the flattened version of array `A` `flatten()` function converts the two-dimensional array `A` into a one-two-dimensional array
`A.flatten()` returns an iterator over the elements of `A`, which allows us
to iterate through each element of the array conveniently
- Check Prime Status of Each Element:
For each element in the flattened array, the code checks whether it's a prime number by calling the `is_prime()` function
If the element is prime (`is_prime(element)` returns `True`), it appends the prime number to the `prime_numbers` list
- Print the List of Prime Numbers:
Finally, after iterating through all elements of the array, the code prints the list `prime_numbers` containing all prime numbers found in the array `A`
1.3 Methodology of solving task 1f:
- Matrix Multiplication:
Trang 8 `np.matmul(C, B)` performs matrix multiplication between matrices
`C` and `B` This results in a new matrix `D`
- Applying Operation on Every Other Row:
`D[::2]` selects every other row of the matrix `D` The slicing notation
`[::2]` means starting from the first row (`0`), it selects every second row
- Reversing Selected Rows:
`D[::2][:, ::-1]` reverses the order of columns for the selected rows The slicing `[:, ::-1]` means reversing the order of columns for all selected rows This effectively reverses the content of every other row
- Assigning Reversed Rows Back to `D[::2]`:
After reversing the selected rows, the code assigns these reversed rows back to the corresponding rows in matrix `D`
- Printing the Modified Matrix:
Finally, the code prints the modified matrix `D[::2]`, which contains the rows that have been reversed
1.4 Methodology of solving task 1g:
- Initialize Variables:
`max_prime_count` is initialized to `0` This variable will hold the maximum count of prime numbers found in any row
`rows_with_max_primes` is initialized as an empty list This list will store the indices of rows with the maximum count of prime numbers
- Iterate Through Rows:
Trang 9 Using a `for` loop, the code iterates through each row of the array `A`
`A.shape[0]` gives the number of rows in `A`
- Count Prime Numbers in Each Row:
Inside the outer loop, there is another nested loop that iterates through each element of the current row
For each element, the code checks if it is prime using the `is_prime()` function If it's prime, `prime_count` is incremented
- Update `max_prime_count` and `rows_with_max_primes`:
After counting prime numbers in the current row, the code compares
`prime_count` with `max_prime_count`
If `prime_count` is greater than `max_prime_count`, it updates both
`max_prime_count` and `rows_with_max_primes` The current row index `i` is appended to `rows_with_max_primes`
If `prime_count` is equal to `max_prime_count`, it means there are multiple rows with the same maximum count of prime numbers In this case, the current row index `i` is also appended to
`rows_with_max_primes`
- Print Rows with Maximum Prime Count:
After iterating through all rows, `rows_with_max_primes` contains the indices of rows with the maximum count of prime numbers
The code then prints the corresponding rows from array `A` using these indices
1.5 Methodology of solving task 1h:
- Initialize Variables:
Trang 10 `max_sequence_length` is initialized to `0` This variable will hold the length of the longest sequence of consecutive odd numbers found in any row
`longest_sequence_rows` is initialized as an empty list This list will store the indices of rows with the longest sequence of consecutive odd numbers
- Iterate Through Rows:
Using a `for` loop combined with `enumerate()`, the code iterates through each row of the array `A` `enumerate()` provides both the index `i` and the row itself (`row`) for each iteration
- Count Consecutive Odd Numbers in Each Row:
Inside the outer loop, there is another nested loop that iterates through each element (`num`) of the current row
For each element, the code checks if it is odd (`num % 2 != 0`) If it's odd, `current_sequence_length` is incremented by 1, indicating the length of the current sequence of consecutive odd numbers
If an even number is encountered, `current_sequence_length` is reset
to 0, as the sequence of consecutive odd numbers is interrupted
- Update `max_sequence_length` and `longest_sequence_rows`:
After counting consecutive odd numbers in the current row, the code compares `current_sequence_length` with `max_sequence_length`
If `current_sequence_length` is greater than or equal to
`max_sequence_length`, it updates both `max_sequence_length` and
`longest_sequence_rows` The current row index `i` is appended to
`longest_sequence_rows`
Trang 11 If `current_sequence_length` is equal to `max_sequence_length`, it means there are multiple rows with the same longest sequence length
In this case, the current row index `i` is also appended to
`longest_sequence_rows`
- Print Rows with Longest Sequence of Consecutive Odd Numbers:
After iterating through all rows, `longest_sequence_rows` contains the indices of rows with the longest sequence of consecutive odd numbers
The code then prints the corresponding rows from array `A` using these indices
Trang 12CHAPTER 2 SOURCE CODES AND OUTPUTS
Matrix A
Figure 1: Matrix A
Matrix B
Figure 2: Matrix B
Trang 13Matrix C
Figure 3: Matrix C
2.1 1a:
Sourcecode of 1 a
Figure 4: Sourcecode of 1 a
Trang 14output of 1 a
Figure 5: output of 1 a
2.2 1b:
Sourcecode of 1 b
Figure 6: Sourcecode of 1 b
Trang 15output of 1 b
Figure 7: output of 1 b
2.3 1c:
Trang 16Sourcecode of 1 c
Figure 8: Sourcecode of 1 c
output of 1 c
Figure 9: output of 1 c
2.4 1d:
Sourcecode of 1 d
Figure 10: Sourcecode of 1 d
output of 1 d
Figure 11: output of 1 d
Trang 172.5 1e:
Sourcecode of 1 e
Figure 12: Sourcecode of 1 e
output of 1 e
Figure 13: output of 1 e
2.6 1f:
Trang 18Sourcecode of 1 f
Figure 14: Sourcecode of 1 f
output of 1 f
Figure 15: output of 1 f
2.7 1g:
Trang 19Sourcecode of 1 g
Figure 16: Sourcecode of 1 g
output of 1 g
Figure 17: output of 1 g
2.8 1h:
Trang 20Sourcecode of 1 h
Figure 18: Sourcecode of 1 h
output of 1 h
Figure 19: output of 1 h