6,361 questions
Best practices
0
votes
3
replies
92
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 ...
0
votes
3
answers
111
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 ...
3
votes
1
answer
128
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, ...
0
votes
0
answers
62
views
Index reference by None in Python [duplicate]
I am currently trying out slicing a string in Python and was confused about how exactly does Python interpret the term 'None' because it behaves rather conveniently when used but I am not how does it ...
5
votes
2
answers
160
views
Performance of list.extend slice vs islice
It seems that even when islice would theoretically be better, in practice, it is slower than just using slice. So I am a bit puzzled by the difference in performance between the usage of slice and ...
1
vote
1
answer
67
views
How to display 3 elements by 3 of an array in HTML using array.sclice() method in javascript
I have found a way to display a portion of an array using arrayName.slice(start, end), i made a funtion to feed the start and end to the slice method so i can use it with onClick button to click next ...
0
votes
2
answers
94
views
Unexpected behavior with array slicing and mask
It was unexpected that
x=np.empty((2,10,5))
x.shape
>>> (2, 10, 5)
x[0].shape, x[0,:,:].shape
>>> ((10, 5), (10, 5))
mask = [True,True,True,False,False]
x[0,:,mask].shape
>>&...
0
votes
0
answers
39
views
Texture Slicing for displaying pseudo 3D planes in XNA/Monogame
currently I'm drawing pseudo 3D road segments to achieve a fake 3D road by drawing lines.
This is what it looks like:
The road is also moving smoothly. Here is my code:
public void Draw()
{
...
1
vote
1
answer
89
views
How do I move as many elements as possible from a Vec into a pre-existing slice?
I have src: Vec<Foo> and dst: &mut [Foo]. I want to move as many elements as possible from src into dst. Specifically:
If src is shorter than dst, then the beginning of dst should be ...
0
votes
1
answer
222
views
Systemd cgroup slice user override does not work
While trying to implement resource limitation (Debian 12) for all users except root user i faced that
user-0.slice MemoryMax does not override user.slice MemoryMax parameter.
root@:/etc/systemd/system....
3
votes
1
answer
113
views
pandas dataframe slicing performance is affected by how subset was previously assigned
In a recent post Pandas performance while iterating a state vector, I noticed a performance when slicing pandas dataframes that i do not understand.
The code presented here does not do anything ...
1
vote
1
answer
87
views
How to properly work (modify and delete) entries on a subset of data from a bigger slice in golang?
Scenario is a game with lots of units placed on a map (tilemap). Some of this units belonging to different empires fight against each other.
Approach was to create a slice of pointers to units to be ...
-1
votes
1
answer
119
views
How to serialize data at an offset from the start of a vector
I want to serialize data into a buffer, but not starting at the first byte, so I tried passing a slice to the serializer.
The serializer works if you pass the whole Vec like this:
let mut buffer = Vec:...
1
vote
2
answers
111
views
Using reflection in Go, how to iterate a known slice
With
m := map[string]any{"a": 1, "b": 2, "c": []int{2, 3, 4}}
v := reflect.ValueOf(m)
How to iterate through "c" in v?
See https://go.dev/play/p/...
1
vote
1
answer
748
views
Read and upload large file (> 2GB) in chunks using JavaScript, without loading entire file into RAM
What JavaScript API should I look for if I want to read a File (e.g. from an <input type="file" ...> or a drop area) in chunks and upload these chunks sequentially - but without ...
-1
votes
4
answers
76
views
Getting elements after each key element occurence PHP Array [duplicate]
I have an array with following elements:
$array = ["START","a","a","a","START","b","b","b","START","c&...
1
vote
1
answer
74
views
Why am I getting an empty string if I use positive start index and negative stop and step index values?
I am trying to run this code snippet:
test="test"
print(test[3:-1:-1])
For the slicing, the start index should start from 3 which is inclusive and stop index should be -1 exclusive which ...
1
vote
2
answers
153
views
How to combine slice assignment, mask assignment and broadcasting in PyTorch?
To be more specific, I'm wondering how to assign a tensor by slice and by mask at different dimension(s) simultaneously in PyTorch.
Here's a small example about what I want to do:
With the tensors and ...
4
votes
1
answer
127
views
Efficient way to delete columns and rows from a numpy array using slicing and not np.delete
Would it be possible given an array A, bad row indices and bad column indices to use slicing to make a new array that does not have these rows or columns?
This can be done with np.delete as follows:
...
4
votes
1
answer
130
views
How do I sort a sequence of slices in a vector?
I have a data structure where conceptually, I have a sequence of tuples of integers, all of the same size. However, this size is not known at compile time, so I can't use actual tuples or arrays or ...
2
votes
1
answer
991
views
Sorting array of strings alphabetically (in ascendending order) in Zig
I want to sort a fruit list alphabetically in ascending order:
const allocator = std.heap.page_allocator;
var list = std.ArrayList([]const u8).init(allocator);
defer list.deinit();
try list.append(&...
1
vote
1
answer
117
views
Go ozzo validation. check if a stuct field is in a slice
I have a struct like:
type Foo string
type Mystruct struct {
currentFoo Foo
foos []Foo
}
I want to validate that currentFoo is in foos. I am doing
func (s MyStruct) ValidateInput() error {
...
1
vote
1
answer
117
views
How can I inverse a slice of an array?
I want to do something along the lines of...
import numpy as np
arr = np.linspace(0, 10, 100)
s = slice(1, 10)
print(arr[s])
print(arr[~s])
How could I apply the "not" operator to a slice, ...
-3
votes
1
answer
126
views
does append empty slice to another slice can process allocation in golang?
i have a small question about 'append' function in golang:
I have a slice1 and a function which calls in for loop and returns some slice2 which can be empty as well. So the question is how golang will ...
-1
votes
1
answer
163
views
Verilog slice direction differs from VHDL
I have a VHDL entity with some unconstrained std_logic_vector ports that is wrapped by a verilog module that clearly defines those port widths.
Verilog wrapper:
module conv_wrapper (din,dout,clk,ce);
...