1

I have sift descriptor matrix like this one:

 a=[[ 0.          0.          0.         ...,  0.01570028  0.11186453
   0.03728818]
 [ 0.19031648  0.18246838  0.0156962  ...,  0.06474684  0.          0.        ]
 [ 0.          0.          0.00392734 ...,  0.06480112  0.17083933
   0.04909176]
 ..., 
 [ 0.09828723  0.0176917   0.00196574 ...,  0.16905404  0.          0.        ]
 [ 0.23960059  0.18657423  0.00589182 ...,  0.00392788  0.          0.01963939]
 [ 0.00392924  0.09430183  0.15913433 ...,  0.00392924  0.01768159
   0.00589386]]
[[ 0.          0.          0.         ...,  0.01570028  0.11186453
   0.03728818]
 [ 0.19031648  0.18246838  0.0156962  ...,  0.06474684  0.          0.        ]
 [ 0.          0.          0.00392734 ...,  0.06480112  0.17083933
   0.04909176]
 ..., 
 [ 0.09828723  0.0176917   0.00196574 ...,  0.16905404  0.          0.        ]
 [ 0.23960059  0.18657423  0.00589182 ...,  0.00392788  0.          0.01963939]
 [ 0.00392924  0.09430183  0.15913433 ...,  0.00392924  0.01768159
   0.00589386]]

and i want to merge a lot of them in the fastest way...how to make it ? Do a list of all of the array's and then with .dstack ? Thanks

edit: ok .dstack doesn't work because the matrix has different dimensions...

for e.g a=[[128 values]...[128 values]], len(a)=300 and b=[[128 values]...[128 values]] len(b)=1000 result should be c=[[128 values]...[128 values]] len(c)=1300

4

1 回答 1

1

二维数组的 Numpy 约定:第一个数字是行数,第二个数字是列数。

>>> import numpy as np
>>> a=np.zeros((2,5))
>>> a
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> a.shape
(2, 5)

使用 vstack 逐行堆叠。

>>> a=np.zeros((300,128))
>>> b=np.zeros((1000,128))
>>> a.shape
(300, 128)
>>> b.shape
(1000, 128)
>>> c=np.vstack((a,b))
>>> c.shape
(1300, 128)
>>> len(c)
1300

Dstack 实际上是一个深度堆栈:

>>> np.dstack((a,a)).shape
(300, 128, 2)

如果您有数组列表:

a=[array1,array2,...,arrayn]
c=np.vstack(a)
于 2013-07-16T16:16:52.177 回答