【发布时间】:2014-06-15 11:07:42
【问题描述】:
我有一个 2D numpy 数组,我想在最后追加行。
append 和 vstack 我都试过了,但无论哪种方式我都会收到如下错误:
'numpy.ndarray' object has no attribute 'vstack'
或者说没有属性append...
这是我的代码:
g = np.zeros([m, no_features])
# then somewhere in the middle of a for-loop I build a new array called temp_g
# and try to append it to g. temp_g is a 2D array
g.vstack((temp_g,g))
我做了g.append(temp_g) 但没有区别,我得到同样的错误,说没有这样的属性。
我第一次声明数组g 的方式有问题吗?
【问题讨论】:
-
vstack是一个 numpy 函数而不是ndarray实例方法np.vstack((g, temp-g))
标签: python arrays numpy append