Template
Finished Homework2.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
'''
|
||||
Author: SJ2050
|
||||
Date: 2021-10-27 13:08:32
|
||||
LastEditTime: 2021-10-27 19:06:32
|
||||
Version: v0.0.1
|
||||
Description: Solution for homework1.3.
|
||||
Copyright © 2021 SJ2050
|
||||
'''
|
||||
import numpy as np
|
||||
|
||||
if __name__ == '__main__':
|
||||
first_row = np.vectorize(lambda x: (x+1)%2)(np.array([i for i in range(8)]))
|
||||
second_row = np.vectorize(lambda x: x%2)(np.array([i for i in range(8)]))
|
||||
mat = np.zeros((8, 8), dtype=np.int)
|
||||
for i in range(0, 8):
|
||||
if i % 2 == 0:
|
||||
mat[i] = first_row
|
||||
else:
|
||||
mat[i] = second_row
|
||||
# print(mat)
|
||||
# beautify output
|
||||
print('—————————————————————————————————')
|
||||
for r in range(8):
|
||||
for c in range(8):
|
||||
print(f'| {mat[r][c]} ', end='')
|
||||
print('|')
|
||||
print('—————————————————————————————————')
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,12 @@
|
||||
# 1.3 创建8x8矩阵,并设置成国际象棋棋盘样式
|
||||
|
||||
## (1). 解题思路
|
||||
|
||||
国际象棋棋盘每一格由黑或白构成,同时,每个格子与其相邻格子的颜色不同,通过观察,偶数行(如果从0开始计数的话)的样式与第0行相同,奇数行的样式与第一行相同,通过循环可以很快的构建一个描述棋盘样式的矩阵出来。
|
||||
|
||||
|
||||
|
||||
## (2). 运行结果
|
||||
|
||||

|
||||
|
||||
Reference in New Issue
Block a user