我希望实现以下行为:
import numpy as np
x = np.array([[1,2],[3,4]])
y = np.array([5, 6])
cbind(x,y) # desired result: np.array([[1,2,5],[3,4,6]])
看起来应该很容易,但我在http://mathesaurus.sourceforge.net/r-numpy.html上找到的选项(concatenate、hstack等)不起作用,例如:
np.hstack((x,y))
提供
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "X/site-packages/numpy/core/shape_base.py", line 288, in hstack
return _nx.concatenate(arrs, 1)
ValueError: all the input arrays must have same number of dimensions