porepy.utils.mcolon module
Efficient numpy.arange for arrays of start and end indices.
- Acknowledgements:
The functions are a python translation of the corresponding matlab functions found in the Matlab Reservoir Simulation Toolbox (MRST) developed by SINTEF ICT, see www.sintef.no/projectweb/mrst/ .
- mcolon(lo, hi)[source]
Expansion of np.arange(a, b) for arrays a and b.
The code is equivalent to the following (less efficient) loop: arr = np.empty(0) for l, h in zip(lo, hi):
arr = np.hstack((arr, np.arange(l, h, 1)))
- Parameters
lo (
np.ndarray, int
) – Lower bounds of the arrays to be created.hi (
np.ndarray, int
) – Upper bounds of the arrays to be created. The elements in hi will not be included in the resulting array.both (lo and hi should either have 1 or n elements. If their size are) –
one (larger than) –
length. (they should have the same) –
Examples
>>> mcolon(np.array([0, 0, 0]), np.array([2, 4, 3])) array([0, 1, 0, 1, 2, 3, 0, 1, 2])
>>> mcolon(np.array([0, 1]), np.array([2])) array([0, 1, 1])
>>> mcolon(np.array([0, 1, 1, 1]), np.array([1, 3, 3, 3])) array([0, 1, 2, 1, 2, 1, 2])