在一个数组中连接多个numpy数组?

时间:2017-06-13 09:41:49

标签: arrays numpy

假设我有很多numpy数组:

a = ([1,2,3,4,5])
b = ([2,3,4,5,6])
c = ([3,4,5,6,7])

我想生成一个新的二维数组:

d = ([[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7]])

我应该编码什么? 我试过用过:

d = np.concatenate((a,b),axis=0)
d = np.concatenate((d,c),axis=0)

它返回:

d = ([1,2,3,4,5,2,3,4,5,6,3,4,5,6,7])

1 个答案:

答案 0 :(得分:4)

如评论中所述,您可以使用np.array功能:

create external table fleet_fh ( breadcrumbs string)
location 's3://.../';

    CREATE VIEW fleetinfo_fh AS
    SELECT envelope, longitudeDeg, latitudeDeg, INPUT__FILE__NAME as filenm
    FROM fleet_fh ac
    LATERAL VIEW json_tuple(ac.envelope, 'MetaData') s as MetaData, LATERAL VIEW json_tuple(s.MetaData, 'SpecificMetaData', 'ReferencePointDeltaAboveGroundM') v as SpecificMetaData, ReferencePointDeltaAboveGroundM, LATERAL VIEW explode(v.SpecificMetaData) vs, LATERAL VIEW json_tuple(vs, 'key', 'value');
    LATERAL VIEW json_tuple(ac.path,'positionEstimate') r as positionEstimate, LATERAL VIEW explode(r.positionEstimate) l, LATERAL VIEW json_tuple(l, 'longitudeDeg', 'latitudeDeg')

在您希望根据“尚未存在”维度进行堆叠的一般情况下,您还可以使用np.stack

>>> import numpy as np
>>> a = ([1,2,3,4,5])
>>> b = ([2,3,4,5,6])
>>> c = ([3,4,5,6,7])

>>> np.array([a, b, c])
array([[1, 2, 3, 4, 5],
       [2, 3, 4, 5, 6],
       [3, 4, 5, 6, 7]])