Skip to content

RFC: zero-dimensional indices array for take #1010

Description

@mdhaber

The standard specifies that the indices array of take must be one-dimensional.

NumPy, PyTorch, JAX, and CuPy all support zero-dimensional indices arrays, too. Of course, all libraries support zero-dimensional (and int) indices for __getitem__.

Should the standard allow zero-dimensional arrays for indices? How about ints?

Activity

  1. kgryte commented on Aug 6, 2026

    @kgryte
    Contributor

    This was discussed previously. See #855.

  2. ev-br commented on Aug 6, 2026

    @ev-br
    Member

    One sticky bit is that the spec requires that

    The output array must have the same number of axes as x

    While major array libraries do not conform for 0D indices:

    In [1]: import jax.numpy as jnp
    
    In [2]: import cupy as cp
    im
    In [3]: import numpy as np
    
    In [4]: for xp in [np, cp, jnp]:
       ...:     x = xp.arange(6).reshape(2, 3)
       ...:     taken = xp.take(x, xp.asarray(0), axis=0)
       ...:     print(xp.__name__, x.ndim, taken.ndim)
       ...: 
    numpy 2 1
    cupy 2 1
    jax.numpy 2 1
    
    
  3. mdhaber commented on Aug 7, 2026

    @mdhaber
    ContributorAuthor

    Oops, sorry I missed that issue.
    This is orthogonal: that is only about a 0-d first argument (x), and this is about a 0-d second (indices) argument.
    And @ev-br's point is valid, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions