Questions tagged [slice]

A slice is a representation of a part of a sequence, usually defined by a reference to the underlying sequence, an index giving the starting position, a length or end position, and optionally a "stride" or "step" value. Please use the tags "object-slicing" for the slicing problem in C++ and "program-slicing" for the analysis technique.

A slice is a representation of a part of a sequence (including, but not limited to, lists, arrays and strings), usually defined by a reference to the underlying sequence, an index giving the starting position, a length or end position, and optionally a "stride" or "step" value.

Further reading:

6208 questions
2
votes
1 answer

I want to implement python list in cpp, but stuck at overloading subscript operator [ ] and comma ,

I want to implement puthon list in cpp, bug do not fin a way to implement pyton's slice operator, e.g.: list[3:7] // sublist including item 3 included to item 7 excluded As colon is not an operator in cpp, we cannot overload it. So I changed my…
2
votes
1 answer

Tensorflow 2 - tf.slice and its NumPy slice syntax incompatible behavior

Question Please confirm if the below is as designed and expected, or an issue of tf. slice, or a mistake in the usage of tf. slice. If a mistake, kindly suggest how to correct it. Background Introduction to tensor slicing - Extract tensor slices…
mon
  • 18,789
  • 22
  • 112
  • 205
2
votes
3 answers

PHP array slice multiple array non functional

The following slices $scpar into two types one containing the first 9 and the second containing former comma separated values from 10 to 18. $scpar9 = array_slice($scpar,0,9); $scpar18 = array_slice($scpar,9,18); We then use a foreach and use…
Walrus
  • 19,801
  • 35
  • 121
  • 199
2
votes
4 answers

Slicing a list with another list

I have a list that like: list = ['a', 'b', 'c', 'd', 'e'] I want to slice, selecting 'a', 'c', 'd'. I try doing: list[0, 2, 3] and I receive an error message that says: 'list indices must be integers or slices, not tuple'. I also tried: list[True,…
alelew
  • 173
  • 3
  • 13
2
votes
1 answer

Multiple slicing assignement with Python

I was reading a post called "Duplicate each member in a list". I found an answer to solve this problem that I can't understand : >>> a = [3, 1, 4, 1, 5] >>> a[:0] = a[::2] = a[1::2] = a[:] >>> a [3, 3, 1, 1, 4, 4, 1, 1, 5, 5] Could you explain me…
SaukratesK
  • 41
  • 3
2
votes
1 answer

Fastest method to find A[not slice] for a numpy array

What is the fastest way to access the values that are at the opposite of a particular given slice? Some code: import numpy as np A = np.arange(2,100000) S = slice(79,78954,34) A[S] #This is all the values I do NOT want. A[?] #All the values I want…
Bobby Ocean
  • 3,120
  • 1
  • 8
  • 15
2
votes
2 answers

Iterative sliced indexing (python) starting form the end : how to avoid "-0" to be equal to "0"?

I have a list (actually a pandas.DataFrame, but let's make it simple), let's say: a = list(range(10)) I have to iterate on it and extract at each loop all the element from the beginning up to a "moving end". I want the whole list at the first…
Songio
  • 325
  • 1
  • 15
2
votes
1 answer

Serialising slice object to JSON creates gibberish

The following code serialises a Go slice into JSON: package main import ( "encoding/json" "fmt" ) type FooType uint8 const ( Zero FooType = 0 One FooType = 1 Two FooType = 2 Three FooType = 3 ) func main() { var…
vddox
  • 182
  • 11
2
votes
3 answers

Slicing strings

In python, I want to slice strings in a list in such a way that first few characters from that list must be removed/spliced out. a=['hello', 'things', 'becoming', 'expensive'] How I can remove the first two characters from each string in the list…
2
votes
2 answers

Slice string in multiple column with same condition

I have multiple column that I need to slice with same condition I can see some solution here but they do not work with multiple column df['x', 'y']=df['x', 'y'].str.slice(0,19) Error AttributeError: 'DataFrame' object has no attribute 'str'
user15212564
2
votes
2 answers

Slice a list of tuple into list of lists if first and another elements are the same Python

I have the following list A including tuples, and I would like to slice A into a list of lists as seen in B. The logic is that if the first and the fourth elements of the tuples are repeating, pack the group as a list inside list A. A = [(1,…
tcokyasar
  • 582
  • 1
  • 9
  • 26
2
votes
3 answers

String slicing in python

I want to slice word from the end.Suppose, I have some line with case sensitives(Upper/lower case) Abc Defg Hijk Lmn Xyz Lmn jkf gkjhg I want to slice them as like below : Abc Defg Hijk Abc Defg Abc Then I need to take each sliced line in…
Big.Bang
  • 33
  • 5
2
votes
0 answers

pythonic way to get the (2,2) for every (4,4) block / grid in nxn numpy array

How to get the (2,2) pixel of every (4,4) block. I know how to get the (0,0) for every (4,4). Sample code as below import numpy as np image = np.arange(12*8).reshape(12,8) print(image) image2 = image2 = image[::4, ::4] print(image2) Output: [[ 0 1…
py_newbie
  • 329
  • 2
  • 9
2
votes
4 answers

Java: finding index of maximum from slice of an array

I have a large array. I have some Java code for identifying indices for start and end points for a subset/slice of that large array. The only information items that I need to retrieve from the selected subsection of the array are the indices and…
CodeMed
  • 9,527
  • 70
  • 212
  • 364
2
votes
2 answers

Rust: can I have a fixed size slice by borrowing the whole fixed size array in a smaller scope in a simple way

I saw the workarounds and they where kinda long. Am I missing a feature of Rust or a simple solution (Important: not workaround). I feel like I should be able to do this with maybe a simple macro but arrayref crate implementations aren't what I am…
1 2 3
99
100