2016-10-16 15 views

回答

1

一种替代方法可以是与reshaping -

x.reshape((-1,) + (1,)*N) # N is no. of dims to be appended 

所以,基本上对于对应于独居尺寸None's,我们使用长度1沿着那些DIMS的形状。对于第一个轴,我们使用的形状为-1将所有元素都插入其中。

采样运行 -

In [119]: x = np.array([2,5,6,4]) 

In [120]: x.reshape((-1,) + (1,)*9).shape 
Out[120]: (4, 1, 1, 1, 1, 1, 1, 1, 1, 1) 
相关问题