cbind(R函数)等效于numpy

sta*_*lax 1 python numpy r cbind

这是我想要的行为:

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]])
Run Code Online (Sandbox Code Playgroud)

似乎应该很容易,但是我在http://mathesaurus.sourceforge.net/r-numpy.html(连接,hstack等)上找到的选项不起作用,例如:

np.hstack((x,y))
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

sta*_*lax 5

更多谷歌搜索发现以下答案/sf/answers/595396091/

np.c_[x,y]
Run Code Online (Sandbox Code Playgroud)

array([[1, 2, 5],
   [3, 4, 6]])
Run Code Online (Sandbox Code Playgroud)

我将其留给StackOverflow样式表,以决定是否应将整个问题重复删除。