[Numpy-discussion] dimension along axis?

Charles R Harris charlesr.harris@gmail....
Mon Apr 13 20:47:37 CDT 2009


On Mon, Apr 13, 2009 at 7:40 PM, Grissiom <chaos.proton@gmail.com> wrote:

> Hi all,
>
> It there a convenience way to get dimension along an axis? Say I have two
> ndarray:
>
> li1 = np.array([2,3,4])
> li2 = np.array([[2,3,4],[5,6,7]])
>
> I know my list is in C order so the two array is the same in someway. But
> li1.shape will give (3, ) and li2.shape will give (2,3). "3" appear in
> different position so it's inconvenient to identify them. Is there anyway to
> get dimension along axis? (In this case should be axis0)
>

You mean something like this?

In [1]: li1 = np.array([2,3,4])

In [2]: li1[np.newaxis,:].shape
Out[2]: (1, 3)

Or maybe like this?

In [3]: li1 = np.array([[2,3,4]])

In [4]: li1.shape
Out[4]: (1, 3)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090413/165ae802/attachment-0001.html 


More information about the Numpy-discussion mailing list