两个重组的numpy.concatenate导致转置形状?

时间:2013-02-14 15:54:48

标签: python numpy concatenation transpose recarray

假设我有两个具有相同dtype但形状不同的numpy数组x1和x2:
x1.dtype = dtype([('fmv', '<f4'), ('delta', '<f4'), ('rho', '<f4', (5,))])
x2.dtype = dtype([('fmv', '<f4'), ('delta', '<f4'), ('rho', '<f4', (5,))])


x1.shape = (10L, 1L)
x2.shape = (10L, 6L)

我想在轴1上连接这两个数组:
y = np.concatenate((x1,x2), axis=1)

这会导致:
y.shape = (10L, 7L)
y['rho'].shape = (5L, 10L, 7L) 错误
为什么场地rho的形状是否已转换?我期待(10,7,5)

更新

               x1.flags | x2.flags | y.flags
C_CONTIGUOUS : True     | True     | False
F_CONTIGUOUS : False    | False    | True
OWNDATA      : False    | False    | False
WRITEABLE    : True     | True     | True
ALIGNED      : True     | True     | True
UPDATEIFCOPY : False    | False    | False


x1.strides = (28L, 28L)
x2.strides = (168L, 28L)
y.strides = (28L, 280L)

<小时/> 我做了一个小脚本,你可以运行来复制结果:
import numpy as np
x = np.zeros((5,3), dtype=np.dtype([('field1','<f8'),('field2','<f8',4)]))
A1 = np.concatenate((np.array(x[0,0], ndmin=1), np.ravel(x[:,1:], order='C')), axis=0)
B1 = np.concatenate((np.tile(np.array(A1[0],ndmin=2), (5,1)), np.reshape(A1[1:], (5,2), order='C')), axis=1)
A2 = np.ravel(x, order='C')
B2 = np.reshape(A2, (5,3), order='C')

B1['field2'].shape = (4L, 5L, 3L) 错误
B2['field2'].shape = (5L, 3L, 4L)

0 个答案:

没有答案