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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
14 views

How to add an object in a sorted slice

I have a slice which contains objets. The slice must be sorted. How to add an object in this sorted slice with Go? type ObjectStruct struct { Mac string InterfaceIndex int ...
ipStack's user avatar
  • 371
0 votes
2 answers
32 views

Struggling with slicing over strings and using list comprehension

I am currently working on a pandas dataframe from a dataset, which includes export and import revenues from and to Germany from 2012 on. For the sake of clarity I would like to add another column &...
Фома Ф's user avatar
0 votes
3 answers
63 views

How is copy function implemented for slices in go?

I want to understand how go's copy function works for slices package main import "fmt" func main() { arr := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} copy(arr[4:], arr[2:]) fmt....
Ebenezer Rahul's user avatar
0 votes
0 answers
6 views

cosmos sdk does not compile with new slices package

While compiling a cosmos sdk project I am getting this /root/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.47.3/runtime/services/reflection.go:60:28: type func(x *descriptorpb.FileDescriptorProto, y *...
najla chamseddine's user avatar
1 vote
0 answers
28 views

Badger Run time error : Slice out of bound range

I am getting this error while running my process for badger. The error is not in process. Its with in badger library. panic: runtime error: slice bounds out of range [-4169358568:] [recovered] ...
Akhilesh mahajan's user avatar
0 votes
1 answer
24 views

dplyr Subsetting rows by groups with multiple thresholds

I am currently trying to answer a fairly straightforward question: List the top 20% of pharmacies (measured by units) within each region. I first measured the amount of products sold per pharmacy, ...
Olaf Odinn's user avatar
2 votes
3 answers
75 views

Why can't I put a slice in a conditional expression, and what can I do instead?

I need to obtain from a list like [1,2,3,4,5,6] and an index number like 2 a series of lists in this fashion: [1,2] [2] [] [3] [3,4] [3,4,5] [3,4,5,6] I found that this for cycle works lst = [1,2,3,4,...
Matteo's user avatar
  • 21
2 votes
2 answers
41 views

How do you iterate over continuous subsequences of a slice that contain equal elements?

I have a sequence of elements of a type which implements PartialEq in a slice. For illustration, let's say it looks like this: let data = [1,1,1,2,2,3,4,5,5,5,5,6]; I would like to iterate over ...
RBF06's user avatar
  • 2,033
0 votes
0 answers
34 views

understanding python slicing [duplicate]

Consider the statements given below pride="Working at Day" print(pride[-2:2:-2]) results in a agi I want to understand what the outcome using [-2:2:-2].
VrxGhost's user avatar
0 votes
0 answers
37 views

Rust &String to &str implicit conversion [duplicate]

Let's consider this code for my question The playground link can be found here https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=400f59f484d86826de5829ba3f29fc89 fn ...
Rodolfo's user avatar
  • 1,091
0 votes
0 answers
5 views

How can I slice a 3D and not get a concatenated error?

I am trying to slice the below 3D, but i'm getting ''Error using horzcat Dimensions of arrays being concatenated are not consistent. Error in Untitled (line 99) slice(X,Y,Z,[F1,V1],xslice,yslice,...
Kabo's user avatar
  • 1
-1 votes
0 answers
43 views

Suppose l1 = [1,2,3,4,5], then why does l1[-1:0] returns empty list? [duplicate]

Suppose I have list l1 = [1,2,3,4,5] Why does l1[-1:0] returns [] but l1[-1:7] returns [5]? What will be step here? Similarly why does l1[0:-2:-1] returns []? If I print l1[-1:], that means my start ...
user0401's user avatar
-1 votes
1 answer
54 views

Range over buffered channel into a slice [closed]

I am having a problem with a Go buffered channel, as I am trying to iterate a value from it and I am getting an error report. Here is the code: package main import ( "fmt" ) func main() { ...
David Lawal's user avatar
0 votes
1 answer
58 views

How to make a python string slicing clone function?

I'm making a library for strings with ansi formatting, and for implementing slicing properly i need a function like this: slicer(start, stop, step, string) that should return the same output as string[...
user316108's user avatar
1 vote
4 answers
73 views

How to skip values in a slice if it matches the condition first time

How to skip the value in slice if the condition is matched once. func main() { cloud := []string{"moon", "earth", "moon-light"} for _, value := range cloud { ...
Roy Mathew's user avatar
-3 votes
0 answers
41 views

Go slices and arrays [duplicate]

I am reading a tour of go https://go.dev/tour/moretypes/9 it says [3]bool{true, true, false} is an array. But I can print cap and len about it q := [6]int{2, 3, 5, 7, 11, 13} fmt.Println(q) fmt....
icn's user avatar
  • 17.2k
0 votes
1 answer
42 views

In JS, does the result of const newArray = oldArray.splice(0) include elements added during execution?

In my JavaScript code, I have a line of code that looks like this: const newArray = oldArray.splice(0); My question is what happens when there are concurrent modifications to oldArray during the ...
Anthony Luo's user avatar
-2 votes
1 answer
41 views

How to slice an array up until a certain element

I have an array containing strings and objects. The strings act as the "title" while the objects that followed them are the "contents". It is arranged this way for virtualization ...
Echo's user avatar
  • 529
0 votes
0 answers
10 views

pytorch 3d tensor slicing with list works only if there is one value or one True value in list

I have a 3d tensor that I want to mask out row-wise using row_mask. Whether a row is to be masked depends on a boolean list, with a True value corresponding to the row to be masked. The code below ...
puddles's user avatar
  • 61
0 votes
0 answers
32 views

Rust: struct with vector of references to another vector of the struct [duplicate]

I defined two structs like these: #[derive(Debug)] struct Slices<'a> { intervals: &'a[u32] } #[derive(Debug)] struct NumbersWithSlices<'a> { numbers: Vec<u32>, ...
MaPo's user avatar
  • 633
-2 votes
1 answer
71 views

Is it safe to keep reference, but not assigning data to an actual variable? [closed]

I want to keep a list of references in a slice, but I couldn't fine any resource online that explains if keeping reference without assigning to a variable is safe or not? I mean, is it possible that ...
moo.duwayne's user avatar
0 votes
0 answers
31 views

PyVista: how to contour on vertical slices?

PyVista has with slices a nice feature to explore a mesh. My question: Is there a way to generate countours on such a slice (let's say in the xz-plane) ? What works fine are contours in the xy-plane ...
pyano's user avatar
  • 1,895
-1 votes
2 answers
43 views

How exactly [:] operator works in tuples in Python? [duplicate]

When I was working with Colorgram Library, I came across a [:] operator that I didn't understand. print(extraction[0]) prints [<colorgram.py Color: Rgb(r=245, g=243, b=238), 64.68350168350169%> ...
MaximusPrima's user avatar
0 votes
2 answers
92 views

How to efficiently delete an element from a slice in Go?

There are several approaches to deleting slice element(-s). But what if I have an application that intensively working with slices. Go slices are optimised very well for adding new elements, but is ...
Eugene Mikhalev's user avatar
0 votes
1 answer
102 views

Accessing a Go slice without panicking

How can I access a slice without panicking when it doesn't have enough elements? I have the following code: str = str[:3] but since its content can vary in length, when it has less than 3 elements it ...
beep's user avatar
  • 1,093
0 votes
0 answers
38 views

Regarding mutable and immutable borrow with lifetime and struct [duplicate]

I want to keep binary data in Struct(e.g., aout) and refer it partially using Slice(e.g., data) In the followings, I created a slice in test2 method and it might be succeeded. However, as show in the ...
Hiro's user avatar
  • 1
1 vote
2 answers
60 views

Slicing and extracting from dataframe

I have a dataframe like below : time power speed state 1 14.00 29 3 1 2 14.01 30 3 2 3 14.02 29 3 3 4 14.03 30 3 4 5 14.04 29 3 5 6 14.05 ...
Karma_X's user avatar
  • 149
1 vote
1 answer
46 views

What are the differences between applying list methods and reassignment on a list slice?

I tried these codes on a list slice a[:] when I was learning list methods: a = list('zyx') a[:].pop() print(a) a = list('zyx') a[:].append('o') print(a) a = list('zyx') a[:].clear() print(a) a = ...
push.up.hoyv's user avatar
0 votes
1 answer
122 views

Go - Copy bytes from uintptr to byte slice at offset

type MINIDUMP_IO_CALLBACK struct { Handle uintptr //not relevant Offset uint64 //The offset for the write operation from the start of the minidump data. Buffer uintptr //A ...
pepperoni's user avatar
  • 119
0 votes
0 answers
40 views

How to transpose a Cython memoryview slice?

I am trying to calculate the transpose of a Cython typed memoryview slice (eg. a 2D part of a 3D array). I am encountering a transpose error specifically when I try to transpose a 2D slice of a 3D ...
Eric's user avatar
  • 25
0 votes
0 answers
11 views

Is it possible to manipulate filtered data and group them together to create a new category in excel?

I am working on crime data in excel and I want to group different crimes description under one category. For example, theft, burglary, robbery in one group and etc. After filtering them, is it ...
Wendy 's user avatar
2 votes
1 answer
40 views

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 ...
darthpool's user avatar
2 votes
1 answer
49 views

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<Letter>, width: usize, height: usize, }...
julien's user avatar
  • 110
1 vote
2 answers
42 views

Shapes of arrays obtained by mixed basic and advanced indexing in NumPy ndarray

Here is the code: import numpy as np x = np.arange(2*32*32*8*16) x = x.reshape(2, 32, 32, 8, 16) print("x-shape=", x.shape) y = x[0, 3:5, 8:10, [1, 2, 3, 4, 5], :] z = x[0][3:5, 8:10, [1, ...
Locutus's user avatar
  • 11
2 votes
1 answer
28 views

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-...
NeStack's user avatar
  • 1,739
9 votes
1 answer
271 views

slice(start, stop, None) vs slice(start, stop, 1)

I was surprised to read here that The start and step arguments default to None since it also says: slice(start, stop, step=1) Return a slice object representing the set of indices specified by ...
Joe's user avatar
  • 707
0 votes
2 answers
49 views

TypeError while operating on list indices in Python

I have the following code: (len(parameters) / 2 The code above returned the error: TypeError: slice indices must be integers or None or have an __index__ method Why is this the case - especially the ...
Lost1's user avatar
  • 990
0 votes
1 answer
17 views

How to copy elements of one pytorch tensor at given indices into another tensor without intermediate allocation or looping

Given import torch a: torch.Tensor b: torch.Tensor assert a.shape[1:] == b.shape[1:] idx = torch.randint(b.shape[0], [a.shape[0]]) I want to do b[...] = a[idx] But without intermediate buffer ...
yuri kilochek's user avatar
-1 votes
1 answer
42 views

difference between make() and []T{} [duplicate]

I'm studying slices in golang and i learn how to initialize slices in two different ways: func main() { slice1 := make([]int, 5, 10) slice1 = append(slice1, 1, 2, 3, 4) slice2 := []int{1, ...
raul dangio's user avatar
1 vote
1 answer
33 views

How do I slice a 2D numpy array using another 2D numpy array that contains indices?

I have a sparse matrix A that is of size (3000,3000), and I have another matrix B that is of size (83068, 2) that contains the indices of the non-zero elements of A. Is it possible to get a resulting ...
itsanhtuanho's user avatar
3 votes
3 answers
120 views

Can we use step in Rust slice?

In python, we can get subarray in odd indexes like: odd = array[1::2] Can we do this in Rust, using simple syntax or any traits? like: let vec = vec![1; 10]; let sli = &vec[0.2.10]; The above ...
Walker's user avatar
  • 33
0 votes
0 answers
16 views

Numpy: how to create a mask (0, 1) of a 2D matrix having left and right limits of reach row?

I'm trying to generate a mask matrix having indepented slices for each row. Starting from a 0 matrix, I want to put a 1 at different slices of each row. The only solution I found is to use a for loop ...
Michele Antonazzi's user avatar
1 vote
1 answer
53 views

Grouping 3 JSONs into a JSON in GO

Now, I am writing GO for REST API Now, I got 3 JSONs (str_data_table / str_all_col / str_all_domain) as below (These json is in slice datatype) str_data_table { "table" : "tablea&...
cyber_g's user avatar
  • 67
1 vote
2 answers
66 views

Where should I put `mutex` in order to delete an element from a slice in Go? The parent or child struct?

Let's say I have two structs as follows: type Device struct { Ports []*TCPPort } type TCPPort struct { ID int State bool Device *Device } When a TCPPort is created, it's appended ...
baris's user avatar
  • 157
2 votes
3 answers
69 views

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 ...
vj sreenivasan's user avatar
0 votes
2 answers
45 views

the size for values of type `[bool]` cannot be known at compilation time, when using IndexMut [duplicate]

I'm trying to use the Bitmap class as a wrapper for bools. As such I want to be able to index using slices and assign to slices. I'm coming from a python background so I'm used to things just working. ...
keymasta's user avatar
1 vote
1 answer
66 views

How to grab a substring from a given string?

Basically I have following strings and I want to grab a sub-string from them. input: RT4_MANGO_AF output: MANGO input: RT4_DF5_WE_APPLE_AF output: APPLE input: TF_WE_BANANA_AF output: BANANA ...
mac's user avatar
  • 865
0 votes
1 answer
21 views

Interactive Dashboard Power BI

Hello i wanna create interactive dashboard using Power BI, that when i click some category on the graph, the other graph will be interactive. But i wanna create interactive dashboard that when i click ...
Rizki Darmawan 's user avatar
0 votes
1 answer
59 views

How to get a sha256 as an `&[u8; 32]`?

The sha256::digest() function returns a String. I can turn this into a [u8; 32] myself, but it seems wasteful for this crate to turn bytes into a hex string, and for me to then turn this hex string ...
fadedbee's user avatar
  • 42.8k
0 votes
1 answer
42 views

How to split a slice into a header array reference and a tail slice?

I'm looking for a function with a signature similar to: split_header_and_tail(buf: &[u8]) -> Option<(&[u8; HEADER_LENGTH], &[u8])> If the supplied slice is too short, the result ...
fadedbee's user avatar
  • 42.8k

1
2 3 4 5
125