You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__index__ should return int(self) if the input is a 0-D array with integer dtype, and raise TypeError otherwise (similar to __int__ except it doesn't work on floating-point arrays). This will allow 0-D integer arrays to be used as indices. While this is not strictly necessary for an array type to support itself as an index, it does mean that things like indexing Python lists with 0-D arrays will work correctly, and it's generally a good Python practice to do this for integer-like types.
The text was updated successfully, but these errors were encountered:
I just did a quick check that NumPy, PyTorch, JAX and TensorFlow all support this behavior. So seems reasonable. Size-1 lists don't support it, so it's not obvious that it should work. But may as well, since it's common practice.
I just noticed that the
__index__
method is missing from the array object specification. See https://www.python.org/dev/peps/pep-0357/.__index__
should returnint(self)
if the input is a 0-D array with integer dtype, and raise TypeError otherwise (similar to__int__
except it doesn't work on floating-point arrays). This will allow 0-D integer arrays to be used as indices. While this is not strictly necessary for an array type to support itself as an index, it does mean that things like indexing Python lists with 0-D arrays will work correctly, and it's generally a good Python practice to do this for integer-like types.The text was updated successfully, but these errors were encountered: