# [Numpy-discussion] 2D array indexing

Gökhan Sever gokhansever at gmail.com
Fri Feb 28 19:54:40 EST 2014

```Thanks Julian. Mistakenly, I have (a[:1:] + a[:1,:])/2 type of construct
somewhere in my code. It works fine, however I wasn't sure if this is
clearer.

On Fri, Feb 28, 2014 at 6:48 PM, Julian Taylor <

> On 01.03.2014 00:32, Gökhan Sever wrote:
> >
> > Hello,
> >
> > Given this simple 2D array:
> >
> > In [1]: np.arange(9).reshape((3,3))
> > Out[1]:
> > array([[0, 1, 2],
> >        [3, 4, 5],
> >        [6, 7, 8]])
> >
> > In [2]: a = np.arange(9).reshape((3,3))
> >
> > In [3]: a[:1:]
> > Out[3]: array([[0, 1, 2]])
> >
> > In [4]: a[:1,:]
> > Out[4]: array([[0, 1, 2]])
> >
> > Could you tell me why the last two indexing (note the comma!) results in
> > the same array? Thanks.
> >
>
>
> if you specify less indices than dimensions the latter dimensions are
> implicitly all selected.
> so these are identical for three dimensional arrays:
> d = np.ones((3,3,3))
> d[1]
> d[1,:]
> d[1,:,:]
> d[1,...] (... or Ellipsis selects all remaining dimensions)
>
> this only applies to latter dimensions in the shape, if you want to
> select all earlier dimensions they have to be explicitly selected:
> d[:,1] == d[:,1,:]
> d[..., 1] = d[:,:,1]
>
>
> as for :1: vs 1:, its standard python rules: start:stop:step, with all
> three having defaults of 0:len(sequence):1
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>

--
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...