如何打印具有数据类型的 numpy 数组?

Sam*_*gha 2 python numpy

当我使用脚本运行以下代码时,我得到,

a = np.arange(4, dtype=object).reshape((2,2))
print(a[:,0]);
Run Code Online (Sandbox Code Playgroud)

结果:[0, 2]。

但是如果我在终端中运行以下代码,我得到,

a = np.arange(4, dtype=object).reshape((2,2))
a[:,0]
Run Code Online (Sandbox Code Playgroud)

结果:数组([0, 2], dtype=对象)

如何在脚本文件中使用 print 方法获得第二个输出?

use*_*ica 5

print默认打印str其参数的表示。您需要repr代表:

print(repr(a[:, 0]))
Run Code Online (Sandbox Code Playgroud)