简体   繁体   English

Python:第3维的Numpy Tile

[英]Python: Numpy tile in the 3rd dimension

I would like to tile my array in 3 dimension in order to obtain the following result: 我想在3维上平铺我的数组,以获得以下结果:

import numpy as np
a = np.array([1,2])

i = 3
j = 2
k = 2

...after tiling...

out = [[[1,1,1]
        [1,1,1]]

       [[2,2,2]
        [2,2,2]]]

I would like to use np.tile some how (here I'm showing an example with a simple 2D array but I have to deal with a much longer one and cicling with 'for' would be too slow) but even combining a reshape() I cannot obtain the result I want. 我想以某种方式使用np.tile(这里我展示了一个具有简单2D数组的示例,但我必须处理更长的数组并以'for'开头将太慢),但是甚至结合了一个reshape( )我无法获得想要的结果。

np.tile(a.reshape(2,1,1), (1,2,3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM