简体   繁体   English

将列(来自向量)绑定为numpy

[英]Bind columns (from vectors) for numpy

The codes are like this: 代码是这样的:

a = numpy.zeros(3)
b = numpy.ones(3)
bind_by_column((a,b))
=> [[0,1],[0,1],[0,1]]

I checked this but don't find the answer 我检查了这个,但找不到答案

Does anyone have ideas about this? 有没有人有这个想法?

np.column_stack np.column_stack

see Numpy: Concatenating multidimensional and unidimensional arrays 请参阅Numpy:连接多维和一维数组

>>> import numpy
>>> a = numpy.zeros(3)
>>> b = numpy.ones(3)
>>> numpy.column_stack((a,b))
array([[ 0.,  1.],
       [ 0.,  1.],
       [ 0.,  1.]])

You can use numpy.vstack() : 你可以使用numpy.vstack()

>>> import numpy
>>> a = numpy.zeros(3)
>>> b = numpy.ones(3)
>>> numpy.vstack((a,b)).T
array([[ 0.,  1.],
       [ 0.,  1.],
       [ 0.,  1.]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM