[Numpy-discussion] howto make from flat array (1-dim) 2-dimensional?
David M. Cooke
cookedm at physics.mcmaster.ca
Sun May 13 07:40:46 EDT 2007
On Sun, May 13, 2007 at 02:36:39PM +0300, dmitrey wrote:
> i.e. for example from flat array [1, 2, 3] obtain
> array([[ 1.],
> [ 2.],
> [ 3.]])
>
> I have numpy v 1.0.1
> Thx, D.
Use newaxis:
In [1]: a = array([1., 2., 3.])
In [2]: a
Out[2]: array([ 1., 2., 3.])
In [3]: a[:,newaxis]
Out[3]:
array([[ 1.],
[ 2.],
[ 3.]])
In [4]: a[newaxis,:]
Out[4]: array([[ 1., 2., 3.]])
When newaxis is used as an index, a new axis of dimension 1 is added.
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca
More information about the NumPy-Discussion
mailing list