def take_nd(arr, indexer, axis=<NUM_LIT:0>, out=None, fill_value=np.nan, mask_info=None,<EOL>allow_fill=True):
<EOL>if is_extension_array_dtype(arr):<EOL><INDENT>return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)<EOL><DEDENT>elif is_datetime64tz_dtype(arr):<EOL><INDENT>return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)<EOL><DEDENT>elif is_interval_dtype(arr):<EOL><INDENT>return arr.take(indexer, fill_value=fill_value, allow_fill=allow_fill)<EOL><DEDENT>if is_sparse(arr):<EOL><INDENT>arr = arr.get_values()<EOL><DEDENT>elif isinstance(arr, (ABCIndexClass, ABCSeries)):<EOL><INDENT>arr = arr.values<EOL><DEDENT>arr = np.asarray(arr)<EOL>if indexer is None:<EOL><INDENT>indexer = np.arange(arr.shape[axis], dtype=np.int64)<EOL>dtype, fill_value = arr.dtype, arr.dtype.type()<EOL><DEDENT>else:<EOL><INDENT>indexer = ensure_int64(indexer, copy=False)<EOL>if not allow_fill:<EOL><INDENT>dtype, fill_value = arr.dtype, arr.dtype.type()<EOL>mask_info = None, False<EOL><DEDENT>else:<EOL><INDENT>dtype, fill_value = maybe_promote(arr.dtype, fill_value)<EOL>if dtype != arr.dtype and (out is None or out.dtype != dtype):<EOL><INDENT>if mask_info is not None:<EOL><INDENT>mask, needs_masking = mask_info<EOL><DEDENT>else:<EOL><INDENT>mask = indexer == -<NUM_LIT:1><EOL>needs_masking = mask.any()<EOL>mask_info = mask, needs_masking<EOL><DEDENT>if needs_masking:<EOL><INDENT>if out is not None and out.dtype != dtype:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dtype, fill_value = arr.dtype, arr.dtype.type()<EOL><DEDENT><DEDENT><DEDENT><DEDENT>flip_order = False<EOL>if arr.ndim == <NUM_LIT:2>:<EOL><INDENT>if arr.flags.f_contiguous:<EOL><INDENT>flip_order = True<EOL><DEDENT><DEDENT>if flip_order:<EOL><INDENT>arr = arr.T<EOL>axis = arr.ndim - axis - <NUM_LIT:1><EOL>if out is not None:<EOL><INDENT>out = out.T<EOL><DEDENT><DEDENT>if out is None:<EOL><INDENT>out_shape = list(arr.shape)<EOL>out_shape[axis] = len(indexer)<EOL>out_shape = tuple(out_shape)<EOL>if arr.flags.f_contiguous and axis == arr.ndim - <NUM_LIT:1>:<EOL><INDENT>out = np.empty(out_shape, dtype=dtype, order='<STR_LIT:F>')<EOL><DEDENT>else:<EOL><INDENT>out = np.empty(out_shape, dtype=dtype)<EOL><DEDENT><DEDENT>func = _get_take_nd_function(arr.ndim, arr.dtype, out.dtype, axis=axis,<EOL>mask_info=mask_info)<EOL>func(arr, indexer, out, fill_value)<EOL>if flip_order:<EOL><INDENT>out = out.T<EOL><DEDENT>return out<EOL>
Specialized Cython take which sets NaN values in one pass

This dispatches to ``take`` defined on ExtensionArrays. It does not
currently dispatch to ``SparseArray.take`` for sparse ``arr``.

Parameters
----------
arr : array-like
    Input array.
indexer : ndarray
    1-D array of indices to take, subarrays corresponding to -1 value
    indices are filed with fill_value
axis : int, default 0
    Axis to take from
out : ndarray or None, default None
    Optional output array, must be appropriate type to hold input and
    fill_value together, if indexer has any -1 value entries; call
    _maybe_promote to determine this type for any fill_value
fill_value : any, default np.nan
    Fill value to replace -1 values with
mask_info : tuple of (ndarray, boolean)
    If provided, value should correspond to:
        (indexer != -1, (indexer != -1).any())
    If not provided, it will be computed internally if necessary
allow_fill : boolean, default True
    If False, indexer is assumed to contain no -1 values so no filling
    will be done.  This short-circuits computation of a mask.  Result is
    undefined if allow_fill == False and -1 is present in indexer.

Returns
-------
subarray : array-like
    May be the same type as the input, or cast to an ndarray.