Is it possible to systematically slice an 1d array of length m by an interval n in numpy? Say I have a list of 1000 values, could I break that into 10 lists of 100 values easily?
SIice a numpy array based on an interval?
1.4k Views Asked by BOUNCE At
2
There are 2 best solutions below
0
NaN
On
array_split allows one to split with unequal spacing as well, should this ever meet your needs
ar = np.arange(0, 20, dtype='int')
s = [2, 7, 12, 17]
np.array_split(ar, s)
Out[80]:
[array([0, 1]),
array([2, 3, 4, 5, 6]),
array([ 7, 8, 9, 10, 11]),
array([12, 13, 14, 15, 16]),
array([17, 18, 19])]
Related Questions in NUMPY
- Why numpy.vectorize calls vectorized function more times than elements in the vector?
- Producing filtered random samples which can be replicated using the same seed
- Numpy array methods are faster than numpy functions?
- When I create a series of spectrograms from a long audio file, the colour intesities vary noticably
- How do I fix a NumPy ValueError for an inhomogeneous array shape?
- How should I troubleshoot "RuntimeWarning: invalid value encountered in arccos" in NumPy?
- Unravel by multi-index/group
- Calculating IRR Using Numpy
- Integrating with an array of upper limits without sacrificing time efficiency
- Why doesn't this code work? - Backpropagation algorithm
- How to remove integers from a mixed numpy array containing sub-arrays and integers?
- How to transfer object dataframe in sklearn.ensemble methods
- Rust cannot borrow as mutable
- Why does the following code detect this matrix as a non-singular matrix?
- How to detect the exact boundary of a Sudoku using OpenCV when there are multiple external boundaries?
Related Questions in SLICE
- String slice in a const function
- 2024 golang a slice of length 2 append 3 more elements, why does it have length 5 capacity 6 instead of capacity 5?
- How to do Python-style array slicing in Java?
- The performance impact of removing elements from the front of the slice
- python replace in string
- Why iterating over slice may be slower than over map in Go?
- How to return a slice in Java
- Adding numpy arrays to cells of a pandas DataFrame depends on initialisation
- How do I determine a slice to make sure it only accepts float32 or uint32?
- slicing pandas columns individually between first and last valid index
- Why slicing of [:0] does not return an error?
- Go, 2-dimensional array (or slice) of struct
- Pandas slicing by index inconsistency
- Index_slicing_problem
- pandas slice 3-level multiindex based on a list with 2 levels
Related Questions in NUMPY-SLICING
- I want to flip an image (with three channels RGB) horizontally just using array slicing. How can I do it with python?
- what is happening in the given numpy code. I'm confused for the last line print() statement
- Unpacking a list in numpy[square brackets]
- pytorch split array by list of indices
- Syntax error when unpacking in NumPy arrays
- Shifting and adding to an array by along and across step intervals
- i installed numpy 1.26.3 but still not able to use np. method
- Python : appened the value of created_date based on the condition
- NumPy Get elements based on starting indices and stride
- How to change object attributes when overloading __getitem__ in np.ndarray subclassing
- Select n'th element along m'th axis on numpy array
- Numpy shape function
- Slice array along axis with list of different indices
- Strange Empty Arrays with Negative Step Slicing in NumPy (v1.23.5)
- How to efficiently slice numpy arrays? (Finite difference method)
Related Questions in PROGRAM-SLICING
- Using Frama-C to slice from a large project
- Is there any way to remove letters from a word starting with a Vowel? Python
- Trouble implementing greater-than/inequality sudoku solver in SWI-Prolog
- Basic string slicing from indices
- SIice a numpy array based on an interval?
- Python: Given a list of integers x, write a single expression that returns True if all odd index values are twice their preceding values
- frama-c slicing plugin appears to discard used stack values
- Solving a puzzle in Prolog about time constraints
- How does the program-slicing plug-in Indus and kaveri work in eclipse?
- How to use WALA for Forward Slicing
- Using FlowDroid programmatically with the Soot framework?
- Program slicing in python
- Slicing a C code with Frama-c
- Slicing with Frama-c
- How to install Impact Analysis Plug-in for Frama-c on Ubuntu 14.04?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
You can use both
np.array_split()andnp.split()which in fact are the same with a little note (as pernp.array_split())From the documentation: