limit_ndarray
- typhon.math.array.limit_ndarray(M, limits)[source]
Select elements from structured ndarray based on value ranges
This function filters a structured ndarray based on ranges defined for zero or more fields. For each field f with limits (lo, hi), it will select only those elements where lo<=X[f]<hi.
>>> X = array([(2, 3), (4, 5), (8, 2), (5, 1)], dtype=[("A", "i4"), ("B", "i4")])
>>> print(limit_ndarray(X, {"A": (2, 5)})) [(2, 3) (4, 5)]
>>> X = array([([2, 3], 3), ([4, 6], 5), ([8, 3], 2), ([5, 3], 1)], dtype=[("A", "i4", 2), ("B", "i4")])
>>> print(limit_ndarray(X, {"A": (2, 5, "all")})) [([2, 3], 3)]
- Parameters:
M (numpy.ndarray) – 1-D structured ndarray
limits (dict) – Dictionary with limits. Keys must correspond to fields in M. If this is a scalar field (M.dtype[field].shape==()), values are tuples (lo, hi). If this is a multidimensional field, values are tuples (lo, hi, mode), where mode must be either all or any. Values in the range [lo, hi) are retained, applying all or any when needed.
- Returns:
ndarray subset of M. This is a view, not a copy.