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
- How can I serialize a numpy array while preserving matrix dimensions?
- store numpy array in mysql
- Trying to save an np array with string and floats, but getting a error
- Does numpy broadcast in *all* of its functions?
- Is there any implementation of hstack in gnumpy
- Mayavi - color vectors based on direction instead of magnitude
- How to install scipy misc package
- Numpy Vs nested dictionaries, which one is more efficient in terms of runtime and memory?
- How to count distance to the previous zero in pandas series?
- Changing the amount of points changes the result of the fft
- Succint way of handling missing observations in numpy.cov?
- Fastest Way to access and put values in matrix
- Enforcing that inputs sum to 1 and are contained in the unit interval in scikit-learn
- Cython speed vs numpy
- Best practice for using common subexpression elimination with lambdify in SymPy
Related Questions in SLICE
- sorting javascript array slice
- A Smarter Way to Learning JavaScript: Chapter 23 - Strings: Finding Segments
- Creating byte buffers in rust
- How to slice (in Python) "all but the last n" items when n may be zero?
- How to slice middle element from list
- Parenthesis after a slice in go?
- What is the difference between a slice and an array?
- Using BLAS ?gemm on a subset of an array in fortran
- The zero value of a slice is not nil
- irregular slicing/copying in numpy array
- Why isn't .slice() working with Float32Array() but does with an Array()? [JavaScript]
- Concatenation of strings array issues in Python: Str(ArrayOfString[1])+" "+Str(ArrayOfString[2]) doesn't seem to work
- How to keep a strong reference in Go?
- Slicing rows of pandas dataframe between
- Python, __getitem__, slices, and negative indexes
Related Questions in NUMPY-SLICING
- Numpy get values at indices given in array form
- Implementing numpy.roll on a flattened array
- why there is a difference in the output of the same indexing selection inside a numpy array
- Having trouble working through more complex array slicing
- Identity mask for numpy ndarray
- Pythonic way of slicing array by list indices
- Confused on Index Slicing in python
- SIice a numpy array based on an interval?
- Combination of slicing and array index in numpy
- Weird result in setting column values of a numpy array
- "IndexError: too many indices for array" when trying to count unique items in numpy array column
- Dividing image into patches and getting patch index of one pixel
- Creating a 3 column Data Frame in Pandas
- Get a list of values from a 3D numpy array using a list of 3-component indices (4D array)
- How to loop over subarrays until the end of a numpy array
Related Questions in PROGRAM-SLICING
- SIice a numpy array based on an interval?
- Is there any way to remove letters from a word starting with a Vowel? Python
- Python: Given a list of integers x, write a single expression that returns True if all odd index values are twice their preceding values
- Using FlowDroid programmatically with the Soot framework?
- Trouble implementing greater-than/inequality sudoku solver in SWI-Prolog
- Program slicing in python
- How to get Data & Control Dependency Slice using Frama-c
- Backward slice generation for a java file
- How to install Impact Analysis Plug-in for Frama-c on Ubuntu 14.04?
- Prolog - get the factors for a given number doesn't stop?
- /*undefined sequence*/ in sliced code from Frama-C
- Slicing using frama-c
- find specific word and read after that word in python
- frama-c slicing plugin appears to discard used stack values
- Basic string slicing from indices
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 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: