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

Method _scalar_heuristic

numpy/ma/core.py:3234–3255  ·  view source on GitHub ↗

Return whether `elem` is a scalar result of indexing `arr`, or None if undecidable without promoting nomask to a full mask

(arr, elem)

Source from the content-addressed store, hash-verified

3232 return not isinstance(m, np.ndarray)
3233
3234 def _scalar_heuristic(arr, elem):
3235 """
3236 Return whether `elem` is a scalar result of indexing `arr`, or None
3237 if undecidable without promoting nomask to a full mask
3238 """
3239 # obviously a scalar
3240 if not isinstance(elem, np.ndarray):
3241 return True
3242
3243 # object array scalar indexing can return anything
3244 elif arr.dtype.type is np.object_:
3245 if arr.dtype is not elem.dtype:
3246 # elem is an array, but dtypes do not match, so must be
3247 # an element
3248 return True
3249
3250 # well-behaved subclass that only returns 0d arrays when
3251 # expected - this is not a scalar
3252 elif type(arr).__getitem__ == ndarray.__getitem__:
3253 return False
3254
3255 return None
3256
3257 if _mask is not nomask:
3258 # _mask cannot be a subclass, so it tells us whether we should

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected