[Numpy-discussion] Which rule makes x[np.newaxis, :] and x[np.newaxis] equivalent?

Nathaniel Smith njs at pobox.com
Tue Dec 12 03:09:19 EST 2017

On Tue, Dec 12, 2017 at 12:02 AM, Joe <solarjoe at posteo.org> wrote:
> Hi,
> question says it all. I looked through the basic and advanced indexing,
> but I could not find the rule that is applied to make
> x[np.newaxis,:] and x[np.newaxis] the same.

I think it's the general rule that all indexing expressions have an
invisible "..." on the right edge. For example, x[i][j][k] is an
inefficient and IMO somewhat confusing way to write x[i, j, k],
because x[i][j][k] is interpreted as:

-> x[i, ...][j, ...][k, ...]
-> x[i, :, :][j, :][k]

That this also applies to newaxis is a little surprising, but I guess


Nathaniel J. Smith -- https://vorpus.org

More information about the NumPy-Discussion mailing list