我想创建一个3D遮罩数组,它是基于一个2维的"深度"数组来表示3维空间中填充深度的程度.我曾希望在NumPy中会有一个向量化的解决方案来解决这个问题,而不是求助于for循环. 例如:
tst = np.arange(1, 10).reshape(3,3) # depths referred to above
blk = np.zeros(shape=(3,3,9)) # the output 3d array to be filled with ones or zeros
以下示例位置的预期结果为:
blk[0,0]
array([1., 0., 0., 0., 0., 0., 0., 0., 0.])
blk[1,2]
array([1., 1., 1., 1., 1., 1., 0., 0., 0.])
blk[2,2]
array([1., 1., 1., 1., 1., 1., 1., 1., 1.])
有谁对此有什么 idea /提示吗?