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

compute median every 12 values

ex_array = [-8.23294593e-02, -4.07239507e-02, 6.08131029e-02, 2.72433402e-02, -4.73587631e-02, 5.15452252e-02, 1.32902476e-01, 1.22322232e-01, 2.71845990e-02, -1.16927038e-01, -2.62239877e-01, -1.46526396e-01, -1.82859136e-01,…
goodname
  • 49
  • 4
2
votes
1 answer

Is there a way to variable slicing in numpy?

I'm trying to slice an array in a variable way. For example, from row 0 up to row 10, slice the array using a step of 2. From row 10 to row 30 slice it using a step of 3. Also, it is worth mentioning that I'm trying to do so without writing any…
rober_dinero
  • 311
  • 2
  • 7
2
votes
1 answer

How to exclude coordinates which overflow matrix

The task is to write a function that returns all its neighbors for an element. Diagonal elements are not considered neighbors. In general, the problem is solved, but if the elements fall outside the matrix, the compiler generates runtime error:…
Victor Bej
  • 81
  • 4
2
votes
0 answers

Do operations on arrays create array temporaries?

Consider the following subroutine, which calculates a sparse matrix product in a Poisson equation solver. SUBROUTINE mut_A_sparse(n, w, v) INTEGER, INTENT(IN) :: n REAL, INTENT(IN) :: w(n*n) REAL, INTENT(OUT) :: v(n*n) v =…
nalzok
  • 14,965
  • 21
  • 72
  • 139
2
votes
1 answer

lazy loading the data from an array object

I'm trying to figure out how to load data (lazy load). First, loads the data lets say 5 records and then when the user clicks the button second time then load another 5 records so it will be 10 records and so on and so forth till the it ends. Peter…
2
votes
2 answers

Not understanding slices and pointers

Current project has me taking a struct (with annotation tags) and writing the data out as a flat file. This file is a columnar file so the positioning of the data is important. These positions and lengths are set up in my struct tags at the field…
Jason Murphy
  • 115
  • 8
2
votes
2 answers

How to filter Selenium results setting a query limit?

I managed to get the data I wanted with selenium, but now I only need the first 17 data that it gives me, I need to make a kind of filter with this data, because I'm going to use conditions on top of them to use in another code. from ctypes.wintypes…
antoniocsk8
  • 71
  • 1
  • 2
  • 6
2
votes
2 answers

How can concatenated &[u8] slices implement the Read trait without additional copying?

The Read trait is implemented for &[u8]. How can I get a Read trait over several concatenated u8 slices without actually doing any concatenation first? If I concatenate first, there will be two copies -- multiple arrays into a single array followed…
Yuri Astrakhan
  • 8,808
  • 6
  • 63
  • 97
2
votes
1 answer

Go: Implementing a ManyDecode for a "set" of individual results

I have implemented a very simple Decode method (using gob.Decoder for now) - this works well for single responses - it would even work well for slices, but I need to implement a DecodeMany method where it is able to decode a set of individual…
Peter
  • 3,144
  • 11
  • 37
  • 56
2
votes
3 answers

Slice in 2 dimensional array

I have 2 dimensional array I want to get every first element in 2 dimensional list. But when I try to using slice I have strange behavior. arr = [[10,2],[11,3],[12,4],[13,4],[14,5]] print(arr[:][1]) Output: [11, 3] arr =…
Vladimir Yanakiev
  • 1,240
  • 1
  • 16
  • 25
2
votes
3 answers

Slicing 2D Python List

Let's say I have a list: list = [[1, 2, 3, 4], ['a', 'b', 'c', 'd'], [9, 8, 7, 6]] and I would like to get something like: newList = [[2, 3, 4], ['b', 'c', 'd'], [8, 7, 6]] hence I tried going with this…
pnuts.93
  • 25
  • 1
  • 6
2
votes
1 answer

Vector assignment to Dask array

I'm trying to change the slice in Dask array row-wise and col-wise way: from dask import array as da A = da.from_array(np.zeros((3,3))) A[[0,1,2], 0] = [1,2,3] A.compute() And I've got: array([[1., 0., 0.], [2., 0., 0.], [3., 0.,…
2
votes
1 answer

Replacing extended slice of a list with another list

I have a list s which looks as below: s = list(range(1, 11)) I am replacing slice of 's' using below code: s[1:4] = [0, 0, 0, 0] print(s) Output: [1, 0, 0, 0, 0, 5, 6, 7, 8, 9, 10] However, when trying to assign the same list [0, 0, 0, 0] to an…
meallhour
  • 13,921
  • 21
  • 60
  • 117
2
votes
1 answer

How to convert type to byte array golang

How to Convert Type of one kind to byte array Here is the working example package main import ( "bytes" "fmt" "reflect" ) type Signature [5]byte const ( /// Number of bytes in a signature. SignatureLength = 5 ) func main()…
anish
  • 6,884
  • 13
  • 74
  • 140
2
votes
4 answers

R - Filtering rows - Keep data between two repeated values

I would like to keep only rows before and after a specific values of a column in my data frame. My data frame below has a structure, where you can see that I have some sort of blocks if I can say so. For example, the data I am interested with always…
Janet
  • 225
  • 1
  • 6