slice Questions
14
I am trying to provide a UI where ranges should be described inclusively. I have human-readable descriptions such as from A to B , which represent ranges that include both end points - e.g. from 2 ...
4
Solved
There is one problem bothering me in Golang.
Say I have 2 structs:
type Dog struct {
Name string
Breed string
Age int
}
type Cat struct {
Name string
FavoriteFood string
Age int
}
And whe...
Concordat asked 19/5, 2015 at 21:39
11
Solved
I have a large list l. I want to create a view from element 4 to 6. I can do it with sequence slice.
>>> l = range(10)
>>> lv = l[3:6]
>>> lv
[3, 4, 5]
However lv is a c...
8
Solved
What is the C# equivalent of Python slice operations?
my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
result1 = my_list[2:4]
result2 = my_list[1:]
result3 = my_list[:3]
result4 = my_list[:3] + my_li...
Hammering asked 19/12, 2013 at 10:7
10
Solved
I'm trying to combine the slice [1, 2] and the slice [3, 4]. How can I do this in Go?
I tried:
append([]int{1,2}, []int{3,4})
but got:
cannot use []int literal (type []int) as type int in appe...
Gordie asked 27/4, 2013 at 4:8
7
Solved
Is there an equivalent of list slicing [1:] from Python in C++ with vectors? I simply want to get all but the first element from a vector.
Python's list slicing operator:
list1 = [1, 2, 3]
list2 ...
3
Solved
I have a pytorch sparse tensor that I need sliced row/column wise using this slice [idx][:,idx] where idx is a list of indexes, using the mentioned slice yields my desired result on an ordinary flo...
Croy asked 3/6, 2018 at 12:30
11
Solved
Why do the following code samples:
np.array([[1, 2], [2, 3, 4]])
np.array([1.2, "abc"], dtype=float)
all give the following error?
ValueError: setting an array element with a sequence.
...
Murdoch asked 12/1, 2011 at 21:58
5
Solved
I'm writing Go application using Go 1.7rc3.
I have a slice of uint64 (var dirRange []uint64) that I want to sort.
The sort package has a function sort.Ints() but it requires []int and I have []uint...
4
Solved
I have a large dataframe (>3MM rows) that I'm trying to pass through a function (the one below is largely simplified), and I keep getting a Memory Error message.
I think I'm passing too large of ...
5
Solved
why do the following lines not work as I expect?
import numpy as np
a = np.array([0,1,2,1,1])
a[a==1][1:] = 3
print a
>>> [0 1 2 1 1]
# I would expect [0 1 2 3 3]
Is this a 'bug' or is ...
Corallite asked 6/11, 2009 at 13:21
3
Solved
A question purely for curiosity's sake. This is obviously invalid syntax:
foo = {}
foo['bar': 'baz']
It's obvious what happened, the developer moved a line out of the dictionary definition but did...
Bertrambertrand asked 11/11, 2010 at 17:26
2
Solved
I want to create an array that contains unique strings. How can I do that?
var paths = make([]string, 0)
func main() {
// Members are added dynamically
paths = append(paths, "aaa")
paths = app...
7
Solved
I thought I understood the basics of list slicing in python, but have been receiving an unexpected error while using a negative step on a slice, as follows:
>>> a = list(range(10))
>&g...
2
Solved
My question is slightly different from this question that asks about how to check equality of Go slices.
Like this article suggests, a Go slice is a value consisting of three things: a pointer to ...
5
Solved
In Go, what is the difference between var s []int and s := make([]int, 0)?
I find that both works, but which one is better?
Rondi asked 28/8, 2014 at 7:51
13
Solved
How can I check if two slices are equal, given that the operators == and != are not an option?
package main
import "fmt"
func main() {
s1 := []int{1, 2}
s2 := []int{1, 2}
fmt.Println...
Cheeseparing asked 9/3, 2013 at 14:46
5
I am creating a FAQ page with accordion buttons, with groups of buttons under sub-headers. I designed it using an ngFor statement in the faq.html file.
<h1>Frequently Asked Questions</h1&g...
Lair asked 16/12, 2021 at 23:16
3
Solved
I have 2 arrays declared as :
var input []string and var output []string .
The input array is filled with some IDs initially. Output array is NULL.
After every iteration I want to remove a rand...
1
Solved
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 ...
11
Solved
I need to make a copy of a slice in Go and reading the docs there is a copy function at my disposal.
The copy built-in function copies elements from a source slice into a
destination slice. (A...
4
Solved
I need to calculate the length of a range, but ideally without creating the range, (hopefully will be faster and use less memory. This is important, because this function will be called a lot). The...
Decal asked 5/8, 2015 at 17:25
6
Solved
In Swift 2, what is the major difference between the three array variants:
Array
ContiguousArray
ArraySlice
Can anyone explain this with a real world example?
19
Solved
Is there anything similar to a slice.contains(object) method in Go without having to do a search through each element in a slice?
3
Solved
In a pub quiz by Dave Cheney I came across the following construct:
a := [...]int{5, 4: 1, 0, 2: 3, 2, 1: 4}
fmt.Println(a)
>> [5 4 3 2 1 0]
(Playground Link)
It seems you can use keys i...
Viewy asked 30/3, 2016 at 7:35
© 2022 - 2025 — McMap. All rights reserved.