def consecutive(data, stepsize=1):
return np.split(data, np.where(np.diff(data) != stepsize)[0]+1)
a = np.array([0, 47, 48, 49, 50, 97, 98, 99])
consecutive(a)
yields
[array([0]), array([47, 48, 49, 50]), array([97, 98, 99])]
More Related Contents:
- Replacing values represented by 'UN' with NaN
- ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- How to find the exact intersection of a curve (as np.array) with y==0?
- How to access the ith column of a NumPy multidimensional array?
- pandas select from Dataframe using startswith
- Concatenating two one-dimensional NumPy arrays
- What’s the fastest way in Python to calculate cosine similarity given sparse matrix data?
- gradient descent using python and numpy
- Sorting a 2D numpy array by multiple axes
- Weighted standard deviation in NumPy
- Vectorized NumPy linspace for multiple start and stop values
- Pandas pd.Series.isin performance with set versus array
- Efficiently detect sign-changes in python
- Efficient way to take the minimum/maximum n values and indices from a matrix using NumPy
- Get week start date (Monday) from a date column in Python (pandas)?
- What is dtype(‘O’), in pandas?
- Python baseline correction library
- How to get faster code than numpy.dot for matrix multiplication?
- numpy float: 10x slower than builtin in arithmetic operations?
- Finding the nearest value and return the index of array in Python
- What is the purpose of meshgrid in Python / NumPy?
- Generating Discrete random variables with specified weights using SciPy or NumPy
- Index 2D numpy array by a 2D array of indices without loops
- How to overplot a line on a scatter plot in python?
- Python: find contour lines from matplotlib.pyplot.contour()
- No speedup when summing uint16 vs uint64 arrays with NumPy?
- Fastest way to compute entropy in Python
- Swapping columns in a numpy array?
- Compute a confidence interval from sample data assuming unknown distribution
- Efficient dot products of large memory-mapped arrays