10,941 questions
1
vote
0
answers
50
views
Jacobi Method on Python stopping at 3rd iteration [closed]
I am trying to code a jacobi algorithm w/o using matrices on python. The code I came up with looks fine but it stops at 3rd iteration even though the error is still pretty much large.
ps. I am not an ...
2
votes
1
answer
121
views
Concatenate Tables Based on Column Information in Python [duplicate]
I have a dataframes pulled from a file. The variable with all these dataframe names is: Data_Tables.
These dataframes all have the same columns, and I want to concatenate the dataframes based on the ...
Best practices
1
vote
7
replies
117
views
How to best group an iterator's items into batches?
Our program reads results of an SQL query and turns each row into a task for a worker to perform. Something like:
for row in query.results():
cluster.submit(row)
However, most of the tasks are so ...
-6
votes
2
answers
123
views
Why does list iterator skip elements after in-place modification using slice assignment
I know that modifying a list while iterating over it is dangerous. For example, using my_list.remove() is a famous problem because it causes the iterator to skip the next element.
However, I found a ...
3
votes
4
answers
212
views
Is there an alternative to `all` that returns Result instead of bool?
Consider an example where one needs to iterate over a sequence with all but the output yes/no requires unwrapping somehow.
pub fn interesting(i : u32) -> Result<bool, ()> {
if i < 42 {
...
3
votes
2
answers
276
views
Is iteration order of a set in Python preserved until that set is modified?
According to the Python documentation, set is a mutable unordered collection.
Usually, it's implemented as a hash table that stores references to objects as its keys. Comparing to dict (which is also ...
-5
votes
1
answer
143
views
calling a class object in an iterative way on python
I made the next class
obj = MyClass()
fds=['a','b','c']
for i in fds:
attribute_name = f"{i}"
setattr(obj, attribute_name, [f"{i}"])
print(obj.i)
I know that obj.i is ...
1
vote
1
answer
116
views
takeWhile equivalent for Kotlin maps
My Kotlin project needs to parse files and keep track of the outcome:
fun parseFiles(dp:MyDataProvider, files:List<String>)
{
//store the status of each processed file
val statusMap = ...
0
votes
2
answers
93
views
python basics: can someone help me understand processing one file vs processing all files at a time?
This will output all csv files from the directory, but only show one of the csv dataframes.
OUTPUT_PATH = "./static/output/"
FILE_LIST = glob.glob("./static/*.json")
def all_data():...
1
vote
1
answer
61
views
Conditional iteration with snakemake and checkpoint
Issue
For my workflow I need to repeat a certain number of rules multiple times, the idea is that with each of these iteration the output gets better and better.
I had issue with adding new jobs to ...
3
votes
1
answer
159
views
Weirdness with foreach() iteration of array data [duplicate]
I have a csv file on the webserver (eg. 5GDPR6LR-1.csv)
The csv file consists of data from an associative array written to file using fputcsv() within a foreach() loop.
The problem occurs when I try ...
1
vote
1
answer
109
views
How to implement insertion into BST iteratively in Rust?
I'm trying to implement an algorithm for insertion into BST (binary search tree) in Rust. I did it recursively, but am having problems implementing the iterative solution. I'm struggling to borrow a ...
1
vote
1
answer
89
views
Is there another way to construct this column in pyspark that avoids an iterative algorithm?
I have two dataframes, df1:
| attribute1 | attribute2 |
| -------- | -------- |
| value1 | value2 |
| value1 | value4 |
This is a dataframe with around 20 million ...
2
votes
1
answer
212
views
Create Iterator Function in Excel VBA
I'm working on implementing a fuzzy-matching function in VBA for a project I'm working on. Ideally, I'd like it to be iterable, since that way I don't have to deal with the headache of holding its ...
0
votes
1
answer
48
views
How to calculate position state in SQL where each row depends on previous calculation?
Sharing a common DolphinDB use case and solution for data processing.
I have a table of stock observation data recording minute-by-minute indicator states, with two key indicators:
ov95: ...
0
votes
2
answers
72
views
Issue Appending " to a List in Python
I am attempting to split a string by each word and symbol into a list. This should put them in separate strings by iteration in the function SplitString().
For example:
display("Hello, World!&...
3
votes
5
answers
198
views
Sequence of function iterations
Is there a way to abuse assignment expressions or functional tools to generate the sequence x, f(x), f(f(x)), ... in one line?
Here are some contrived examples to demonstrate:
def iter(x, f, lim=10):
...
-1
votes
1
answer
126
views
How to iterate through a list of lists and access each element in the sublist and store for use in functions?
I'm working in Python and I'm trying to generate coordinates for circles with their radii being appended after coordinate generation. Once I have the list I want to check it against itself to see if ...
1
vote
1
answer
49
views
iteratively decrease values in observations for a grouped dataset without changing observations in the first rows using group_map and return a tibble
I am attempting to decrease the values of the value column by 0.000001 for observations that are not in the first row into a new column called lagged.values. I then want to fill the NAs resulting from ...
1
vote
4
answers
97
views
Implementing iteration in Standard SQL (BigQuery)
I have an audit table (with tablename, date and rec counts) with data as far back as 5 yrs as shown below. My requirement is to retrieve the record counts for the tablename for a specific day and it's ...
-1
votes
1
answer
49
views
for planets in Planet: TypeError: 'type' object is not iterable [closed]
I'm working through an example and cannot see the solution.
Can someone please point me in right direction?
Tried lots of stuff.
File "C:\Python prog\orbit.py", line 57, in main
for ...
2
votes
1
answer
141
views
get the index of a C++ foreach item in a debugger
Lets assume the code doesn't need the index, but something interesting happened during debugging and I want to know the position of the item in the container.
for (int item : myarray)
doSomething(...
-3
votes
1
answer
53
views
How can I write the values of a decision variable to an Excel sheet after running an iterative optimization in CPLEX OPL?
I am performing an iterative optimization using the main function in CPLEX OPL. After each iteration, I want to write the values of the decision variables to an Excel sheet. The optimization runs for ...
2
votes
0
answers
101
views
Array copies one too many values if there is an empty line in the input file?
Working on an assignment for my coding class which involves the function below, which is supposed to read quiz scores from an input file and put up to 12 of them into an array. I've narrowed down the ...
1
vote
2
answers
133
views
For a custom Mapping class that returns self as iterator, list() returns empty. How do I fix it?
The following is a simplified version of what I am trying to do (the actual implementation has a number of nuances):
from __future__ import annotations
from collections.abc import MutableMapping
...
0
votes
0
answers
51
views
Jacobi method converges faster than Gauss-Seidel in case of Laplace equation
It is need to solve the problem using the Jacobi method: d^T/dx^2 + d^2T/dy^2 = 0 with conditions at the boundaries of the square:
T(0, y) = 1, T(x, 1) = 1, dT/dx(1, y) = 1 - y, dT/dy(x, 0) = x.
...
0
votes
1
answer
53
views
How can I update a matrix in the current iteration while preserving the values from previous iterations using the main function in CPLEX OPL?
I want to update a matrix with values of the current iteration as well as the previous iteration in the main function. Please help me in achieving this. I have tried this code.
int TSlots = 96;
...
2
votes
1
answer
63
views
How to update a matrix in iterative optimization using cplex opl?
I am solving an iterative optimization problem in cplex opl using the main function. However, I am getting errors while printing a matrix value. Please help me in solving this issue.
int Nod=41;
...
-4
votes
2
answers
144
views
Iterating over JSON containing lists of dictionaries in python [closed]
Please help in providing a solution to iterate through a JSON response containing lists of dictionaries in python:
{
"cart": [
{
"id": "0Zy2jwLzQzlk7xq3",
...
3
votes
4
answers
222
views
Fastest way to find indices of highest value in a matrix iteratively and exclusionarily
For the sake of anyone who stumbles upon this in the future, I apologize – I had conceived of the problem and solution incorrectly. A proper implementation of finding the coordinates of pairwise best ...
1
vote
1
answer
45
views
How to include .dat file while writing a code in cplex opl using main function?
I am trying to solve an iterative optimization problem in cplex opl using main function. The optimization objective and constraints are written in subvaluenew.mod.
float maxOfx = ...;
dvar float x;
...
0
votes
1
answer
56
views
How to update non-decision variables/parameters Iteratively in CPLEX OPL using main function?
I am running a CPLEX OPL model for 10 entities. The objective is to optimize a certain objective for each entity.
Step 1: The CPLEX model first runs for the first entity, optimizing the objective ...
-1
votes
1
answer
54
views
Batch: Accessing array by variable index
I'va got a folder with an extract of PowerPoint slides, named Folie1.png, Folie2.png ...
Within a batch script I'd like to crop and rename them into known names. These names are given in an "...
2
votes
2
answers
100
views
How to write an R function that iterates through a data frame of formulas to fit multiple model variations
I have a list of many combinations of model variables that I'm testing for model fit. I need to figure out how to write an R code that iterates through each one in the model fit. This is what I have ...
2
votes
2
answers
92
views
How to change in place the values of a data class object through an iteration, Kotlin
I am looking for a way, without having to install a new library, to iterate through a Kotlin data class and to change the values according to their type.
The implementation I would like is the ...
0
votes
4
answers
172
views
Iterate over vec of iterators in parallel
Say I've got a Vec that looks something like [[1,2,3],[4,5,6],[7,8,9]]. How would I iterate over all the inner vecs at once? That is,
for k in some_func([[1,2,3],[4,5,6],[7,8,9]]) {
println!("...
1
vote
2
answers
94
views
R Iteratively modify values based on previous row if a condition is met
Here is a sample of my df:
library(dplyr)
# Create the dataframe
df <- data.frame(
id = c('A', 'A', 'A', 'B', 'C', 'C', 'C', 'C', 'D', 'D', 'D'),
supply_start_date = as.Date(c('2024-01-01', '...
0
votes
2
answers
70
views
Iterate through a list in chunks [duplicate]
I need to call an API interatively, but the api endpoint limits me to 100 calls per minute. I have a list which is used as the data for an API call (I'm using requests to call the API).
Lets say the ...
0
votes
1
answer
129
views
Azure DevOps API isn't returning any workItems for an Iteration
Using the Azure DevOps REST API, I am trying to get a list of all the workItems associated with each Iteration, but am mostly getting an empty return.
I start with the following call to get the list ...
-1
votes
1
answer
76
views
pandas get min and max value for multiple rows
i have these cols "Price", "functions", & "cat" as df.
Price functions cat
51272.85 8 3-8
51134.15 3 3-8
51150 8 3-8
51161.3 1 1-6
51165.45 1 ...
0
votes
1
answer
94
views
Sudden reduction in python iteration speed after 10 seconds
I am writing some code in python to find out the first natural number which does not appear in the first billion digits of pi. Here's what I've written:
import datetime
from tqdm import tqdm
def ...
0
votes
4
answers
107
views
How to iterate through nested json objects with unique names in Apps Script
Given a json file with nested objects (not arrays) like:
{
"data": {
"UniqueName1": {
"name": "Bob",
"title": &...
1
vote
1
answer
91
views
Using one dataframe to find matching combinations in fixed sets
A
B
C
D
E
Key 1
1
-1
Key 2
1
-1
Key 3
1
-1
Key 4
-1
1
Key 5
1
-1
Key 6
1
-1
Key 7
1
-1
Key 8
1
-2
1
Final Result
A
B
C
D
E
1
-1
suppose we have the above dataframe where each key is an option ...
0
votes
1
answer
82
views
Remove struct from vector while mutably iterating through it
Relevant Code:
for watermelon in self.watermelons.iter_mut() {
if watermelon.clr == Color::RED {
self.score += 1;
self.watermelons.remove(*self.watermelons.index(watermelon));
}...
1
vote
0
answers
105
views
Fast(est) method to iterate through pairs of indices in Python, using numpy
I'm constructing a graph with ~10000 nodes, each node having metadata that determine which other nodes it will be connected to, using an edge.
Since the number of edge possibilities (~50M) is far ...
1
vote
1
answer
84
views
How should I convert this recursive function into iteration?
I have a recursive function in the following form:
def f():
if cond1:
...
f()
elif cond2:
...
I've "mechanically" converted it to an iterative function like ...
0
votes
2
answers
90
views
Print incrementing integer as part of a string
I am trying to get a list of scores from user input. I want each prompt to include the current game number, which will increment from 1 to the total number of games. For example, if the user wants to ...
0
votes
1
answer
86
views
How can these specific functions be convereted from using recursion to using iteration?
I've been working on porting a library from C to CUDA. Two functions that I need to port make use of recursion, which CUDA doesn't seem to be playing nicely with. I therefore want to convert these ...
0
votes
0
answers
53
views
Finding a way to iterate using the input of two xarray dataarrays when chunked
I am developing a relatively large model using xarray and therefore want to make use of chunks. Most of my operations run a lot faster when chunked but there is one that keeps running (a lot) slower ...
1
vote
0
answers
27
views
How to evaluate elements of a character vector inside a function in R to dynamically create data variables? [duplicate]
I have a dataset similar to this:
library(tibble)
df <- data.frame(
basket = c("A1", "A2", "A3", "A4", "A5", "A6", "A7", &...