MCPcopy Create free account
hub / github.com/numpy/numpy / take

Method take

numpy/ma/core.py:6066–6090  ·  view source on GitHub ↗

(self, indices, axis=None, out=None, mode='raise')

Source from the content-addressed store, hash-verified

6064 return super().argpartition(*args, **kwargs)
6065
6066 def take(self, indices, axis=None, out=None, mode='raise'):
6067 """
6068 """
6069 (_data, _mask) = (self._data, self._mask)
6070 cls = type(self)
6071 # Make sure the indices are not masked
6072 maskindices = getmask(indices)
6073 if maskindices is not nomask:
6074 indices = indices.filled(0)
6075 # Get the data, promoting scalars to 0d arrays with [...] so that
6076 # .view works correctly
6077 if out is None:
6078 out = _data.take(indices, axis=axis, mode=mode)[...].view(cls)
6079 else:
6080 np.take(_data, indices, axis=axis, mode=mode, out=out)
6081 # Get the mask
6082 if isinstance(out, MaskedArray):
6083 if _mask is nomask:
6084 outmask = maskindices
6085 else:
6086 outmask = _mask.take(indices, axis=axis, mode=mode)
6087 outmask |= maskindices
6088 out.__setmask__(outmask)
6089 # demote 0d arrays back to scalars, for consistency with ndarray.take
6090 return out[()]
6091
6092 # Array methods
6093 copy = _arraymethod('copy')

Callers 15

test_take_outputMethod · 0.80
test_take_object_failMethod · 0.80
test_attributesMethod · 0.80
test_take_refcountMethod · 0.80
tst_basicMethod · 0.80
test_raiseMethod · 0.80
test_clipMethod · 0.80
test_wrapMethod · 0.80
test_byteorderMethod · 0.80
test_record_arrayMethod · 0.80

Calls 4

getmaskFunction · 0.85
__setmask__Method · 0.80
filledMethod · 0.45
viewMethod · 0.45

Tested by 15

test_take_outputMethod · 0.64
test_take_object_failMethod · 0.64
test_attributesMethod · 0.64
test_take_refcountMethod · 0.64
tst_basicMethod · 0.64
test_raiseMethod · 0.64
test_clipMethod · 0.64
test_wrapMethod · 0.64
test_byteorderMethod · 0.64
test_record_arrayMethod · 0.64