Finished Homework2.

This commit is contained in:
SJ2050cn
2021-10-29 23:58:21 +08:00
parent b34436ca5c
commit 19681c61d6
28 changed files with 325 additions and 0 deletions
@@ -0,0 +1,17 @@
'''
Author: SJ2050
Date: 2021-10-26 13:44:25
LastEditTime: 2021-10-26 13:52:13
Version: v0.0.1
Description: Solution for homework 1.1.
Copyright © 2021 SJ2050
'''
import numpy as np
if __name__ == '__main__':
mat = np.array([[10, 34, 54, 23],
[31, 87, 53, 68],
[98, 49, 25, 11],
[84, 32, 67, 88]])
mat_padded = np.pad(mat, ((1, 1), (1, 1)), 'constant', constant_values=((0, 0), (0, 0)))
print(mat_padded)
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@@ -0,0 +1,12 @@
# 1.1 用0填充数组边界
## (1). 解题思路
`numpy`库中提供了一个名为`pad`的方法,可以用来填充数组的边界,其提供的功能非常多,可以指定上下左右边界的宽度,并且可以填充为最小值、平均值、常值等等。这个题目只需把上下左右的边界宽度置为1,且用0填充即可。
## (2). 运行结果
![](images/result.png)