【发布时间】:2016-09-27 04:42:48
【问题描述】:
我正在尝试使用 np.append 追加到一个 numpy 数组。
例如,
a = np.array([1])
np.append(a, [2])
此代码在终端中运行良好(结果为 array([1, 2])),但当我运行包含其中包含的相同代码的 .py 文件时,它将无法运行。当我在附加 [2] 后打印 a 时,它仍然是 [1]。
这是我的 test.py 文件的代码:
import numpy as np
a = np.array([1])
print(a)
np.append(a, [2])
print(a)
这是用终端运行的结果:
python test.py
[1]
[1]
没有错误的错误结果。 有谁知道可能是什么问题?
【问题讨论】:
标签: python arrays numpy append