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

Idiomatic way to slice a Perl array by value rather than index

I have a piece of code that extracts a slice from one of two large arrays of sorted integers, representing stopping points in the program's workflow. I'll include one of the two here. The basic idea is that I'm trying to slice a work range out of…
happy5214
  • 21
  • 2
2
votes
4 answers

Slicing 2D numpy array periodically

I have a numpy array of 300x300 where I want to keep all elements periodically. Specifically, for both axes I want to keep the first 5 elements, then discard 15, keep 5, discard 15, etc. This should result in an array of 75x75 elements. How can this…
Mike
  • 51
  • 5
2
votes
2 answers

How to check if interface is a a pointer to a slice

I know how to check if an interface is a pointer: func isPointerArray(i interface{}) bool { if i == nil { return false } if reflect.ValueOf(i).Kind() != reflect.Ptr { return false } } But how can I check if that…
Ado Ren
  • 3,511
  • 4
  • 21
  • 36
2
votes
1 answer

Go - Graphql : Convert String! in [String!]

I'm trying to query wikiJS Graphql API in go using this client and I have a little problem of type conversion (maybe because of my lack of skills in go and graphql). I have this struct type : var query struct{ Pages struct{ List struct{ …
2
votes
1 answer

How can I make a method that is called with square brackets?

1. What I need I have a Python class called List which has a list named mylist as attribute. class List: def __init__(self): self.mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9] Now I want to make a method named slice that has the same properties…
2
votes
3 answers

How to slice Python Pandas groupby objects with various lengths?

Creating the dataframe: df = pd.DataFrame({'Set': [1, 1, 1, 2, 2, 2, 2, 2], 'Value': [1, 2, 3, 1, 2, 3, 4, 5]}) results in the DataFrame as shown below. Next I perform a groupby operation by Set, and the first group is shown below. grouped_by_Set =…
H. Vabri
  • 314
  • 1
  • 2
  • 13
2
votes
2 answers

How to convert the string representation of a Terraform set of strings to a slice of strings

I've a terratest where I get an output from terraform like so s := "[a b]". The terraform output's value = toset([resource.name]), it's a set of strings. Apparently fmt.Printf("%T", s) returns string. I need to iterate to perform further…
2
votes
1 answer

julia arrays select the first x rows by group

Using julia, I want to select the first x rows of an array per group. In the following example, I want the first two rows where the second column is equal to 1.0, then the first two rows where the second column is equal to 2.0, etc. XX =…
djourd1
  • 459
  • 4
  • 14
2
votes
2 answers

How to create a column that starts with and end with string value in another column?

How do I create a column that starts from "\"" and ends in "]" in another column? For example A new_column \\loc\ggg.x]ddj \\loc\ggg.x] +\\lol\lll.d]aaa \\lol\lll.d] I tried doing this df['new_column'] =…
helpme
  • 163
  • 3
  • 9
2
votes
2 answers

Exporting graphic elements with transparent backgrounds in Fireworks

I've started using Fireworks to do prototypes, but now I need to code a prototype in HTML/CSS. I have all relevant image elements sliced, but the default behavior for Fireworks seems to be to export slides with any visible background elements…
zkwsk
  • 1,960
  • 4
  • 26
  • 34
2
votes
2 answers

Slice method with condition within loop in React

I want to render 0 to 3 items if a state is false and 4 to end of array length if state is true by clicking See more I have the following piece of code but it's erroring out: {items .filter((item) => DateTime.fromISO(item.date).year…
RandomDeveloper
  • 833
  • 2
  • 9
  • 31
2
votes
2 answers

Conditionally merge lines in text file

I've a text file full of common misspellings and their corrections. All misspellings, of the same intended word, should be on the same line. I do have this somewhat done, but not for all misspellings of the same word. misspellings_corpus.txt…
StressedBoi69420
  • 1,376
  • 1
  • 12
  • 40
2
votes
4 answers

How does this Ruby app know to select the middle third of sentences?

I am currently following Beginning Ruby by Peter Cooper and have put together my first app, a text analyzer. However, whilst I understand all of the concepts and the way in which they work, I can't for the life of me understand how the app knows to…
Tom
  • 2,065
  • 5
  • 20
  • 21
2
votes
2 answers

Was this possible in Python before [any previous version]

I remember vaguely that this thing was working a long time ago Does anybody know that if this code really worked before? and if this was deprecated since any newer python version? code # My python version is 3.8 lst = ['a', 'b', 'c', 'd'] lst[0:3]…
codingsenpi
  • 71
  • 1
  • 6
2
votes
1 answer

How can I modify a part of bigger slice (or Vec) by passing another smaller slice?

How can I correctly implement this code below? let mut bigger: [u8; 100] = [0u8; 100]; let smaller: [u8; 3] = [1, 2, 3]; // do something like: // bigger[0..3] = smaller;