numpy的:沿着一个新的轴扩展数组? [英] numpy: extending arrays along a new axis?

查看:411
本文介绍了numpy的:沿着一个新的轴扩展数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

肯定有一种方法可以做到...我无法解决.

Surely there must be a way to do this... I can't work it out.

我有一个(9,4)数组,我想在第3轴上重复4096次...因此,它变成了简单的(9,4,4096),其中每个值都直接来自9,4数组沿新轴重复4096次.

I have a (9,4) array, and I want to repeat it along a 3rd axis 4096 times... So it becomes simply (9,4,4096), with each value from the 9,4 array simply repeated 4096 times down the new axis.

如果我的可疑3D​​图有意义(对角线是z轴)

If my dubious 3D diagram makes sense (the diagonal is a z-axis)

4|   /off to 4096
3|  /
2| /
1|/_ _ _ _ _ _ _ _ _ 
   1 2 3 4 5 6 7 8 9

欢呼

为澄清起见,这里的重点是针对新轴的4096个行"中的每个重复(9,4)数组.想象一个横截面-每个原始(9,4)阵列都是4096长方体中的一个.

Just to clarify, the emphasis here is on the (9,4) array being REPEATED for each of the 4096 'rows' of the new axis. Imagine a cross-section - each original (9,4) array is one of those down the 4096 long cuboid.

推荐答案

这是一种方法:

import scipy
X = scipy.rand(9,4,1)
Y = X.repeat(4096,2)

如果X仅给您(9,4),则

If X is given to you as only (9,4), then

import scipy
X = scipy.rand(9,4)
Y = X.reshape(9,4,1).repeat(4096,2)

这篇关于numpy的:沿着一个新的轴扩展数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆