use*_*627 0 python arrays numpy append
我有一个2D numpy数组,我想在最后添加行.
我已经尝试了两种方法append,vstack但无论哪种方式,我都会收到如下错误:
'numpy.ndarray' object has no attribute 'vstack'
Run Code Online (Sandbox Code Playgroud)
或者它说没有属性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))
Run Code Online (Sandbox Code Playgroud)
我做了g.append(temp_g)但没有区别,我得到同样的错误,说没有这样的属性.
我第一次声明数组的方式有什么问题g吗?
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([5, 6, 7])
>>> np.vstack(a, b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: vstack() takes exactly 1 argument (2 given)
>>>
>>> np.vstack((a, b))
array([[1, 2, 3],
[5, 6, 7]])
Run Code Online (Sandbox Code Playgroud)