nlcpy.take

nlcpy.take(a, indices, axis=None, out=None, mode='wrap')[ソース]

Takes elements from an array along an axis.

When axis is not None, this function does the same thing as "fancy" indexing (indexing arrays using arrays); however, it can be easier to use if you need elements along a given axis. A call such as arr.take(indices, axis=3) is equivalent to arr[:,:,:,indices,...].

Parameters
aarray_like

The source array.

indicesarray_like

The indices of the values to extract. Also allow scalars for indices.

axisint, optional

The axis over which to select values. By default, the flattened input array is used.

outndarray, optional

If provided, the result will be placed in this array. It should be of the appropriate shape and dtype.

mode{'wrap', raise', 'clip'}, optional

In the current NLCPy, this argument is not supported. The default is 'wrap'.

Returns
outndarray

制限事項

  • mode != 'wrap': NotImplementedError occurs.

Examples

>>> import nlcpy as vp
>>> a = vp.array([4, 3, 5, 7, 6, 8])
>>> indices = [0, 1, 4]
>>> vp.take(a, indices)
array([4, 3, 6])

In this example, "fancy" indexing can be used.

>>> a[indices]
array([4, 3, 6])

If indices is not one dimensional, the output also has these dimensions.

>>> vp.take(a, [[0, 1], [2, 3]])
array([[4, 3],
       [5, 7]])