打印时如何从矩阵中删除科学计数法

发布于 2025-01-16 16:50:06 字数 2049 浏览 0 评论 0原文

game_data = '1. e3 e5,2. Qh5 Qf6,3. Qf3 Nc6,4. Qxf6 Nxf6,5. Nf3 d6,6. g3 Nb4,7. Bg2 Nxc2+,8. Kd1 Nxa1,9. b4 Bd7,10. Bb2 Ba4+,11. Kc1 Nc2,12. d4 exd4,13. exd4 d5,14. Nfd2 Bxb4,15. Nf3 Ne4,16. Ba3 Nxa3,17. Nxa3 Bxa3+,18. Kb1 Nc3+,19. Ka1 Bc2,20. Rc1 Bxc1,21. Ne5 Na4,22. Bxd5 Bb2#'
game_data_split = game_data.split(',')
#print(game_data_split)

alphabet = 'abcdefgh'

#below is just a chess board
board = [
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
]

for item in game_data_split:
    #we are going to have to add something to deal with check as a boolean changing every move, or in the middle of every move if white is put in check
    turn,white,black = item.split()
    if white == 'O-O-O':
        x = [0,1,2]
        y = 0
        board[x][y] += 0.1
    if white.endswith('+'):
        x = alphabet.index(white[-3])
        y = int(white[-2]) -1
        board[y][x] += 0.01
    elif white.endswith('#'):
        x = alphabet.index(white[-3])
        y = int(white[-2]) -1
        board[y][x] += 0.001
    else:
        x = alphabet.index(white[-2])
        y = int(white[-1]) - 1
    board[y][x] += 0.00001
    if black == 'O-O-O':
        x = [5,6,7]
        y = [7]
        board[y][x] += 1
    if black.endswith('+'):
        x = alphabet.index(black[-3])
        y = int(black[-2]) -1
        board[y][x] += 10
    elif black.endswith('#'):
        x = alphabet.index(black[-3])
        y = int(black[-2]) -1
        board[y][x] += 100
    else:
        x = alphabet.index(black[-2])
        y = int(black[-1]) - 1
    board[y][x] +=1000
    print(turn)
    pprint(board)

我正在构建一个棋盘可视化器来学习,我的结果似乎正确显示,但我不断得到像 1e-05 甚至 3.0000000000000004e-05 这样的结果。我真的不想在我的结果中使用这种科学记数法。如何让印制板停止显示科学计数法?

game_data = '1. e3 e5,2. Qh5 Qf6,3. Qf3 Nc6,4. Qxf6 Nxf6,5. Nf3 d6,6. g3 Nb4,7. Bg2 Nxc2+,8. Kd1 Nxa1,9. b4 Bd7,10. Bb2 Ba4+,11. Kc1 Nc2,12. d4 exd4,13. exd4 d5,14. Nfd2 Bxb4,15. Nf3 Ne4,16. Ba3 Nxa3,17. Nxa3 Bxa3+,18. Kb1 Nc3+,19. Ka1 Bc2,20. Rc1 Bxc1,21. Ne5 Na4,22. Bxd5 Bb2#'
game_data_split = game_data.split(',')
#print(game_data_split)

alphabet = 'abcdefgh'

#below is just a chess board
board = [
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
]

for item in game_data_split:
    #we are going to have to add something to deal with check as a boolean changing every move, or in the middle of every move if white is put in check
    turn,white,black = item.split()
    if white == 'O-O-O':
        x = [0,1,2]
        y = 0
        board[x][y] += 0.1
    if white.endswith('+'):
        x = alphabet.index(white[-3])
        y = int(white[-2]) -1
        board[y][x] += 0.01
    elif white.endswith('#'):
        x = alphabet.index(white[-3])
        y = int(white[-2]) -1
        board[y][x] += 0.001
    else:
        x = alphabet.index(white[-2])
        y = int(white[-1]) - 1
    board[y][x] += 0.00001
    if black == 'O-O-O':
        x = [5,6,7]
        y = [7]
        board[y][x] += 1
    if black.endswith('+'):
        x = alphabet.index(black[-3])
        y = int(black[-2]) -1
        board[y][x] += 10
    elif black.endswith('#'):
        x = alphabet.index(black[-3])
        y = int(black[-2]) -1
        board[y][x] += 100
    else:
        x = alphabet.index(black[-2])
        y = int(black[-1]) - 1
    board[y][x] +=1000
    print(turn)
    pprint(board)

I am building a chess board visualizer to learn and my results seem to be coming out correctly but I keep getting results like 1e-05 or even 3.0000000000000004e-05 . I really don't want this scientific notation in my results. How can I get the printed board to stop displaying with scientific notation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2025-01-23 16:50:06

我在此链接中找到了答案。

只需将以下代码行放入您的程序中:

np.set_printoptions(suppress=True)

该行之后打印的任何矩阵都将抑制科学记数法。

I found the answer in this link.

Just put the following line of code in your program:

np.set_printoptions(suppress=True)

Any matrix printed after that line will have scientific notation suppressed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文