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
2 answers

Cut a navigation bar with different colors (with CSS 2.1)

Please help me cut the following navigation bar using CSS2.1, with shadow, rounded borders and without spoiling the layout if you zoom-in/zoom-out: Already two days I have been working on it, and could not find any way which will look the same look…
Karine
  • 587
  • 1
  • 11
  • 24
2
votes
2 answers

Dynamically slice a string using a variable

I am trying to slice a string and insert the components into a list (or index, or set, or anything), then compare them, such that Input: abba Output: ['ab', 'ba'] Given a variable length of the input. So if I slice a string word = raw_input("Input…
Christopher W
  • 139
  • 2
  • 2
  • 8
2
votes
1 answer

Which way is faster to copy an array of objects: slice or clone?

This is related to: How do I pass the value instead of the refererence of an array? I need to send the value instead of reference to an array. To that question I got 2-3 valid answers. One was use slice, second (and third was similar) was to use…
zozo
  • 8,230
  • 19
  • 79
  • 134
2
votes
1 answer

mongo slice, what's the default ordering, can it be changed

Mongo has the nice operator $slice, which let's you only retrieve a sub sets of an entiry's embedded array. From their official docs: db.posts.find({}, {comments:{$slice: 5}}) // first 5 comments db.posts.find({}, {comments:{$slice: -5}}) // last 5…
Shivan Dragon
  • 15,004
  • 9
  • 62
  • 103
2
votes
1 answer

slicing multi-dimensional numpy arrays with arrays

I have a numpy array (we'll call it test) of ~286 x 181 x 360, and need to extract a 3-D array from it. The ranges needed for the three dimensions are defined as other numpy arrays (a_dim, b_dim, and c_dim) (based ultimately on user input).…
Topher Hughes
  • 365
  • 3
  • 8
2
votes
4 answers

NSString Slicing in Objective C (right to left)

How can I substring an NSString with the last x characters? Right to left. In python it takes only one line! >>> "string"[-4:] 'ring'
Martino
  • 103
  • 1
  • 7
2
votes
2 answers

data.frame slicing

I hope this question is not too simple for this board. I have created a data.frame df: CAS Name CID 89 13010-47-4 Lomustine 3950 90 130209-82-4 Latanoprost 5311221,5282380,46705340,3890 91 130636-43-0 …
R.newbie
  • 45
  • 4
2
votes
1 answer

Function to Convert int slice to Custom int slice pointer type in Go

I want to take an int slice as an input to a constructor and return a pointer to the original list, type casted into my external custom type(type IntList []int). I can do this: type IntList []int func NewIntListPtr(ints []int) *IntList { x :=…
darthpool
  • 41
  • 4
2
votes
1 answer

How to return slice of a vector in a struct

I want to return a slice of my vector, but the compiler is complaining that &[Letter] needs an explicit lifetime. struct Board { board: Vec, width: usize, height: usize, } impl std::ops::Index for Board { type Output…
julien
  • 100
  • 6
2
votes
1 answer

In pandas adding a time offset to a subset of the dataframe has no effect

I noticed a strange behaviour of the pandas package, that leads to an unexpected failure to add time offsets in some cases. Suppose I have the following dataframe: df = pd.DataFrame({'time': ['2022-01-24', '2022-02-24', '2022-03-24'], …
NeStack
  • 1,739
  • 1
  • 20
  • 40
2
votes
3 answers

low and high bounds of slice

My code snippet package main import "fmt" func main() { s := []int{2, 3, 5, 7, 11, 13} fmt.Println("check 1: ",s, len(s)) s = s[1:4] fmt.Println("check 2: ",s, len(s)) s = s[3:5] fmt.Println("check 3: ",s, len(s)) …
vj sreenivasan
  • 1,283
  • 13
  • 15
2
votes
1 answer

Why is numba slicing so much faster than numpy slicing?

def test(x): k = x[1:2] l = x[0:3] m = x[0:1] @njit def test2(x): k = x[1:2] l = x[0:3] m = x[0:1] x = np.arange(5) test2(x) %timeit test(x) %timeit test2(x) 776 ns ± 1.83 ns per loop (mean ± std. dev. of 7 runs,…
Klaus3
  • 153
  • 5
2
votes
1 answer

In Pandas Multiindex, how do you do an indexslice without knowing the position of the level?

I have a program that works with pandas dataframes, using a multiindex of 2 levels (dates and data) such as: Date_Time Data date1 a b c date2 a b c date3 a b …
byrey3
  • 25
  • 4
2
votes
1 answer

Remove element method doesnt work in Golang

I have a simple code for removing element from slice: package main import "fmt" func main() { values := []string{"1", "2", "3", "4", "5"} valuesResult := removeElementByIndex(values2, 0) fmt.Printf("%v - %v\n", values,…
Neighbourhood
  • 166
  • 3
  • 13
2
votes
1 answer

Difference between [T], &[T]

I want to know the difference between a slice ([T]) and a reference to a slice (&[T]). I do not get how slices are unsized types, can't the compiler deduce the size of a slice through the source code? I understand we need a reference to a slice to…