About 87,900 results
Open links in new tab
  1. slice - How slicing in Python works - Stack Overflow

    The first way works for a list or a string; the second way only works for a list, because slice assignment isn't allowed for strings.

  2. Python: slicing a multi-dimensional array - Stack Overflow

    Feb 27, 2023 · To slice a multi-dimensional array, the dimension (i.e. axis) must be specified. As OP noted, arr[i:j][i:j] is exactly the same as arr[i:j] because arr[i:j] sliced along the first axis …

  3. How to slice a list in Python - Stack Overflow

    Dec 17, 2021 · To trim in-place, use del on a slice; e.g. del listobj[-x:] will remove the last x elements from the list object. – Martijn Pieters Commented Aug 18, 2016 at 14:09

  4. python - How to extract multiple slices in an array ... - Stack Overflow

    I need to extract data from multiple positions in an array. A simple array would be:- listing = (4, 22, 24, 34, 46, 56) I am familiar with slicing.

  5. How to get last items of a list in Python? - Stack Overflow

    Nov 23, 2019 · Python slicing is an incredibly fast operation, and it's a handy way to quickly access parts of your data. Slice notation to get the last nine elements from a list (or any other …

  6. python - Numpy slice of arbitrary dimensions - Stack Overflow

    I would like to slice a numpy array to obtain the i-th index in the last dimension. For a 3D array, this would be: slice = myarray[:, :, i] But I am writing a function where I can take an array of …

  7. How to slice a list from an element n to the end in python?

    To my understanding, python slice means lst[start:end], and including start, excluding end. So how would i go about finding the "rest" of a list starting from an element n? Thanks a lot for all …

  8. list - Index all *except* one item in python - Stack Overflow

    Oct 10, 2013 · Is there a simple way to index all elements of a list (or array, or whatever) except for a particular index? E.g., mylist[3] will return the item in position 3 milist[~3] will return the …

  9. Slicing a list using a variable, in Python - Stack Overflow

    May 13, 2012 · I ran across this recently, while looking up how to have the user mimic the usual slice syntax of a:b:c, ::c, etc. via arguments passed on the command line. The argument is …

  10. python - How do I split a list into equally-sized chunks ... - Stack ...

    Sep 29, 2016 · Then, for each chunk at index i, we are generating a sub-array of the original array like this: a[ i * CHUNK : (i + 1) * CHUNK ] where, i * CHUNK is the index of the first element to …

Refresh