Python 从numpy 1D数组列表创建numpy 2D数组

Python 从numpy 1D数组列表创建numpy 2D数组,python,numpy,Python,Numpy,在尝试从某个numpy数组创建numpy 2D数组时,我遇到了numpyarray的异常行为。下面是示例代码- x = [] x.append(x1) x.append(x2) x.append(x3) x = np.array(x) print x1.shape, type(x1) print x2.shape, type(x2) print x3.shape, type(x3) print x.shape, type(x) print x[0].shape, type(x[0]) (1

在尝试从某个numpy数组创建numpy 2D数组时,我遇到了
numpy
array的异常行为。下面是示例代码-

x = []
x.append(x1)
x.append(x2)
x.append(x3)
x = np.array(x)

print x1.shape, type(x1)
print x2.shape, type(x2)
print x3.shape, type(x3)
print  x.shape, type(x)
print x[0].shape, type(x[0])

(1318,) <type 'numpy.ndarray'>
(1352,) <type 'numpy.ndarray'>
(1286,) <type 'numpy.ndarray'>
(3,) <type 'numpy.ndarray'>
(1318,) <type 'numpy.ndarray'>

为什么,我在第一种情况下看不到2d数组?

如果每个数组的长度相等,您确实会看到您期望的2d形状-正如您在评论中提到的,您应该相应地重新采样


当前构造的数组“锯齿数组”必须与常规Python列表类似,并且不支持类似于
.sum()
的好东西

使用类似的锯齿状数组


缺乏对锯齿状数组的支持是因为NumPy针对具有固定维度的数字数组进行了优化

你希望第一个阵列是什么形状?每个组件的长度不相等。wtf!!!我得到了它。我需要先对所有数据重新采样。。。。
x1 = np.arange(4)
x2 = np.arange(4,8)
x3 = np.arange(8,12)
x.append(x1)
x.append(x2)
x.append(x3)
x = np.array(x)

print x.shape
(3, 4)
>>> x.sum()
ValueError: operands could not be broadcast together with shapes (4,) (3,)