gpt4 book ai didi

python - numpy 中的 set_printoptions() 错误

转载 作者:行者123 更新时间:2023-12-01 01:51:50 25 4
gpt4 key购买 nike

我正在尝试使用 numpy 打印带有额外空格的眼矩阵,例如输入“3 3”,我得到

[[ 1.  0.  0.]
[ 0. 1. 0.]
[ 0. 0. 1.]]

我的这个程序的代码如下

 import numpy
numpy.set_printoptions(sign =' ')
N, M = input().split(' ')
print(numpy.eye(int(N), int(M)))

但是我收到类型错误

TypeError: set_printoptions() got an unexpected keyword argument 'sign'

我使用 python 3.5.2 和 PyCharm Community Edition 2017.1.3 作为 IDE。我的代码在 python 3 的在线编辑器上运行得很好。那么这是我的 IDE/python 安装问题还是 numpy 中的问题?

最佳答案

问题出在 numpy 版本上,正如 jasonsharper 的评论中所述。从 numpy 版本 1.12 升级到 1.14,代码现在工作正常。

关于python - numpy 中的 set_printoptions() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com