Question

Why does the name of np.ix_ contain a trailing underscore?

Was it helpful?

Solution

I can't give a complete reason, but it's for symmetry with np.r_, np.c_, etc. I can make a guess for the overall reason:

All of the short numpy operators like np.r_, np.ix_, etc are oriented towards interactive use.

Therefore, it's common (although not advisible) to do from numpy import * in an interactive console.

r, c, ix, etc, are likely to be variable names. Therefore, they're probably suffixed with _ to prevent getting clobbered when a user defines a variable named r or ix in an interactive session after doing from numpy import *.

OTHER TIPS

ix_ is found in numpy.lib.index_tricks

This module is attributed to:

# Written by Konrad Hinsen <hinsen@cnrs-orleans.fr>
# last revision: 1999-7-23
#
# Cosmetic changes by T. Oliphant 2001

It was write many years ago, and incorporated as legacy component in the current numpy. The names were chosen by one programmer many years ago, and never changed to fit Python community standards.

From the .ix_ doc:

Using ix_ one can quickly construct index arrays that will index the cross product.

My guess: 'i' for 'index', 'x' for 'cross', '_' to avoid confusion with a (potentially) common indexing variable name.

Similarly named objects from the same module are r_, c_ and s_. Technically they are not functions, since they are not callable (don't take ()). But they are indexable (take []). They are actually instances of classes that have __getitem__ definitions. ogrid and mgrid are also indexable objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top