6,355 questions
Tooling
0
votes
3
replies
150
views
How do I delete a slice element
I'm in the process of learning Golang, and I'm currently trying to create a Todo project.
My knowledge is limited to the GO base.
Please take a look at my code and tell me how I can delete a task.
The ...
Score of 2
3 answers
139 views
Finding unique 1D arrays and corresponding 2D index pairs in 3D array (with numpy)
I have a 3D numerical array X, of shape=(N,N,6); and a 2D logical array mask, of shape=(N,N). I would like to find all unique 1D subarrays (length=6, along axis=2) of X, searching over the first two ...
Advice
0
votes
7
replies
172
views
Brute force vs optimal approach to find the second largest number in a slice (Go)
I’m looking to understand both:
A brute force solution
An optimal solution (in terms of time and space complexity)
The input is a slice of integers, for example:
nums := []int{10, 5, 20, 8, 15}
...
Score of 1
1 answer
133 views
odin(idioma): the preferred way to compare slices
If i would compare by references i can deal with raw_data from
What is the preferred method of comparing values?
I think it's too generic to not exist in std...
// Maybe I can make `return false` on `...
Score of 1
1 answer
167 views
How to split a slice at a given index, then move the remaining elements into a boxed slice without copying or cloning?
We have a boxed slice of an arbitrary type T. I'd like to slice it at a given index, then move the remaining elements after the index into a new Box<[T]>. It's fine if the original Box<[T]>...
Score of 10
2 answers
360 views
Why is it not possible to replace part of a global vector in this example?
R version 4.5.0 (2025-04-11 ucrt)
RGui console in Windows 11.
I happened to come across the following problem.
Consider the global assignment statement:
xxx <<- c(1,2)
xxx[1:2]
ls()
This gives
[...
Advice
0
votes
2
replies
95
views
slicing html text based on length of plain text
I have a problem where I need to cut off text based on a max length. But the inputted string could be html a la <p>hello</p>. the html tags do not count towards the max length.
for example ...
Score of 1
1 answer
193 views
Cause of AlignmentMismatch error while using bytemuck?
I'm facing an AlignmentMismatch error while trying to cast a Vec<u8> to Vec<T>, where T is a struct that uses repr(C) and Pod + Zeroable.
I've also tried the slice road &[u8] -> &...
Best practices
0
votes
3
replies
117
views
How to safely move data within a slice in Go?
If I define a slice as follows then it will have a length of 0 and a capacity of 10:
var logs = make([]string, 0, 10)
After appending data to this slice, I check to see if it is at capacity and if it ...
Score of 3
1 answer
155 views
How do I cast a *mut T to a *mut [T]?
In Rust, both references and pointers to unsized types have metadata indicating the actual type of the reference. For example, a *mut [T] consist of a pointer to the start of a slice, plus a length ...
Score of 0
4 answers
181 views
How to slice first char from all iterable records in a string (converted from list)
I'm trying to remove the first/last two characters of each iterable record in a string (which I converted from a list and split into separate lines).
newString = "\n".join([str(item) for ...
Score of -3
2 answers
177 views
Slice the extension `'.txt'` from file names [duplicate]
I was trying to slice the extension '.txt' from some file names.
It look like the Python cut the last letter - before the dot- if its a t or x:
filenames = ["report.txt", "downloads....
Score of 3
1 answer
158 views
Sequence association vs. modern Fortran interfaces
Consider the following (traditional) Fortran code, which performs matrix-vector multiplication z = X y, but instead of the full matrix, we exclude the top two rows:
subroutine matrix_vector_product(m, ...
Score of 0
1 answer
71 views
Get image to actually tile in storyboard same as it does for SwiftUI [duplicate]
So I have this code in SwiftUI, it's working great.
.background(
Image("felt")
.resizable(resizingMode: .tile)
...
Score of 3
1 answer
288 views
How is range over slices.All() different from just range over a slice?
In the Go Tour we have
var pow = []int{1, 2, 4, 8, 16, 32, 64, 128}
func main() {
for i, v := range pow {
fmt.Printf("2**%d = %d\n", i, v)
}
}
which outputs:
2**0 = 1
2**1 ...