Questions tagged [iteration]
Iterations are the successive repetitions in loops such as for, foreach or while. Questions with this tag are often concerned about how to best handle a collection of data.
10,559
questions
0
votes
0
answers
10
views
Coordinates translation using list comprehension in python
I'm trying to translate coordinates to center them over Brussels. Due to the specific structure of my variable I don't know how to iterate over them. Please can someone explain me how I could proceed ...
0
votes
0
answers
25
views
Use np.nditer as zip
I have tried to apply the function np.nditer() like zip() with arrays of different dimensions, where the iterator should use only the first dimensions.
Minimal example
a_all = np.arange(6).reshape(2,3)...
2
votes
2
answers
57
views
Iterate through columns with conditions
I have the following info in a dataframe in python
From that dataframe, I require another dataframe that summarizes the information of all the students per state per age.
In other words, instead of ...
1
vote
2
answers
42
views
Unique occurrence of period within the list
I'm using the textwrap module to split my string into a list with width = 40. Then, I'm trying to iterate through the list and after every 2nd period, type "We hit second period" and then ...
-2
votes
0
answers
47
views
How Can I Fix Thousands Of Iterations in Python? [closed]
guys (with this code below) it does thousands of iterations until it finally finds the answer how can i make so that it wont do that much iterations:enter image description here
0
votes
2
answers
49
views
Combinations of words and digits with specific order
I need all possible combinations of upper words and digits in this format digit-word-word-word . I tried this code :
upper_a = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'...
0
votes
1
answer
19
views
pyarrow: fast way to iterate ChunkedArray? (from a table)
The array contains python objects and is part of a table. I need to perform a calculation element-wise. The calculation itself returns a list of numbers which should then be new columns in the table.
...
0
votes
1
answer
24
views
Is there a way to check the value of previous value in iteration? dart
In the below code ,variable modelMap returns a map and I am iterating through that
var modelMap = parsedJson.values;
modelMap.forEach((element) {
modelName = element["ModelName"];
...
0
votes
0
answers
9
views
How do I use hashcats best64 rule in my python tool?
I have been searching for quite a while, but I couldn´t find any explanation of the best64 rule. I downloaded the tool and opened the file called "best64" which contains the rule. Can ...
1
vote
2
answers
27
views
In R, how do I make a long dataset that contains all the categories that a row applies to?
I have a dataset of students, and I want to create a column that categorizes each student based on their and other students' data in their "subject" and "grade_letter" column ...
-1
votes
0
answers
16
views
pandas dataframe average for last "x" rows if value changes in row "x+1" [closed]
How can I calculate the average for the last x rows (all with the same value) and set this average for all x rows? When the value changes I want to calculate the new average.
what I've tried:
a = 0
...
0
votes
1
answer
16
views
iteration calculation based on another dataframe
How to do iteration calculation as shown in df2 as desired output ?
any reference links for this > many thanks for helping
df1
a b c
0 1 0 5
1 9 9 2
2 2 2 8
3 6 3 0
4 6 1 7
df2 ...
0
votes
1
answer
30
views
How do I iterate over a column dataframe made of lists with an index made of other column dataframe?
So I have a dataframe with different columns. I want to use three. One is a list of different sizes, other two are two columns made of just one number. I want to create a new column made of the ...
1
vote
2
answers
47
views
In R, how can I get the sum for all combinations of two variables?
I have a long dataset with students grades and subjects. I want to keep a long dataset, but I want to add a column that tells me how many Fs a student had in their humanity courses (English & ...
0
votes
0
answers
37
views
Iterate over nested Map in groovy
after hours of endless trying of solving this problem, I feel completely lost in this.
I have 2 maps, one contains environments and the other contains several jobs which i need to iterate through and ...
1
vote
2
answers
70
views
How to subtract value in one row of pandas Data Frame from value in another row without for loop?
I have a python pandas Data Frame with 2 columns: X, which is an angle (181 evenly-spaced values between 0 and 360), and R1, which is an electrical resistance measured for a given angle. I need to add ...
0
votes
2
answers
57
views
How to print words that are not in the list
I have 2 files, the first one is a list of tweets. And the second one is a list of standard words which looks like this:
acoustics
acquaint
acquaintable
tbc....
I want to iterate through the list of ...
1
vote
1
answer
92
views
Find the minimum iterations in a loop - BigQuery
I'm trying to establish a code in BigQuery SQL to find the minimum iterations needed to cover all items.
In details, say I have a table with 3 columns: Site, Router, PC.
Each site has multiple routers ...
-3
votes
2
answers
54
views
How do I loop through a dictionary and a variable to see if certain values are 2 apart in a for loop? [closed]
Essentially the point of it is to check through a password (str) and loop through a dictionary containing the alphabet and see if there are 3 consecutive letters in order in the password so that I can ...
1
vote
1
answer
48
views
TypeError : 'int' object is not iterable
I'm trying to preprocess video frames for anomaly event detection. The model is already trained but I can't figure out the issue with the following code (I'm a beginner). Please help with this ...
-2
votes
1
answer
34
views
How to iterate through 3 parameters to find the largest value? [closed]
public Person getOldest(Person personA, Person personB, Person personC) {
A method passes in 3 parameters of object Person in which Person can use the getAge() method. I'm trying to find the oldest ...
1
vote
2
answers
48
views
iteration and count variable in ansible
I am trying to simplify the code
- name: Report status
ansible.builtin.debug:
msg:
- "{{ agents.results.0.services.0.display_name }} is {{ agents.results.0.services.0....
-1
votes
3
answers
74
views
Find element in list n times Python
Given are
a = [1, 4, 2, 5]
b = [[[0, 1]], [[0, 2]], [[0, 3]], [[0, 4]], [[0, 5]], [[0, 6]], [[0, 2]], [[0, 3]], [[0, 4]], [[0, 5]], [[0, 4]],
[[0, 5]], [[0, 6]], [[0, 4]], [[0, 2]], [[0, 2]], [[...
1
vote
2
answers
64
views
Creating a box in Java from user inputs, but how do I replace the interior of the box with a different input than its borders?
I need to create a box using user inputs. My inputs are the dimensions (height x width), the "interior" (the character that the box is filled with), and the "border" (the character ...
1
vote
2
answers
25
views
Mimicing 'n' Nested For Loops Using Recursion
I would like to create some number of for-loops equal to the length of a list, and iterate through the values in that list. For example, if I had the list:
[1,2,3,4]
I would like the code to function ...
1
vote
3
answers
58
views
How to translate a LOOP into a DO inside a macro (common lisp)?
I'm currently reading through Seibel's "Practical common lisp" and found this example macro:
(defmacro check (&rest forms)
`(progn
,@(loop for f in forms collect `(do-stuff ,f ',f))...
0
votes
0
answers
20
views
Array and object iteration in JavaScript? [duplicate]
This is my code:
// Task 1
var dairy = ['cheese', 'sour cream', 'milk', 'yogurt', 'ice cream', 'milkshake']
const logDairy = () => {
for (const item of dairy) {
console.log(item);
}
}
...
2
votes
2
answers
43
views
combining elements of 2 list in a certain way [duplicate]
i have a doubt in combining 2 lists into one in a certain way.
can anyone help me out?
i have 2 lists
a = ['a', 'b', 'c', 'd', 'e']
b = [1, 2, 3]
i want the resultant list like ['a1', 'b2', 'c3', 'd1'...
0
votes
1
answer
77
views
How to iterate a condition in a while loop? Beanshell
Edited from my original post because I found a work around.
I'm trying to use a while loop to check if inputs exist. I have inputs that can vary in size, meaning I can have one input in a case or ...
0
votes
0
answers
33
views
LogisticRegression not iterating through combinations of features in a dataframe to find the best combination
I wrote a function to find the best combination of given dataframe features, f1 score, and auc score using LogisticRegression. The problem is that when I try to pass a list of dataframes combinations, ...
0
votes
0
answers
20
views
How to make a for loop for training and testing a model iteratively based on the cluster value
I am looking to do a transferability analysis on my clustered data. My goal is to train the model on one cluster ("group") in the data and test on each other group. The end result should be ...
0
votes
1
answer
20
views
Access data (create a list) through a loop - iteration over fieldname (import from Matlab into Python)
I want to create a list from a matlab struc as follows:
#Import
mat2=sio.loadmat('TestData.mat',squeeze_me=True,struct_as_record=False)
#Solution without a loop
v1 = mat['pyDMD'].v1)
.
.
.
v17 = mat['...
-1
votes
0
answers
24
views
How to iterate a custom class to a pandas datetime dataframe based on different days
I am new to the python world and I hope someone from this community is able to help me out.
I have a pandas dataframe with finacial data of a security reported every minute for every day.
for every ...
-1
votes
0
answers
50
views
For loop in Python pointing at previous line
I have a txt file with thousand of rows.
These rows are combined in groups in the sense that the first line of one group always start with the letter "A", then there are one or more lines ...
2
votes
1
answer
31
views
Why logical operations in dataframe iteration doesn't return the right values?
I'm trying to perform a logic test on two dataframes. If zero is included in the delimited interval between dataframe elements, the label 'Not Significant' must be included, otherwise, if zero is not ...
-1
votes
2
answers
48
views
While loop in js faulty
I'm creating a guess the number with limited guesses. I have add an incrementor to check the number of times a user submits an answer. Everything seems to work except the loop starts at the final ...
0
votes
1
answer
51
views
Iterate through array in Cypress with assertions JavaScript
I have an array from API call response that looks like this:
[
{
"IsDatalakeEnabled": true,
"RecoveryHr": {
"IsRecoveryHREnabled": false,
...
-2
votes
1
answer
39
views
How to make calculations and checks on array elements/pixels manually and fast?
To be more clear, I produced a 2-D occupancy map, where obstacles marked with white pixels, from 3-D depth data using Python (NumPy) as given in the following figure.
Occupancy Map
However, ...
1
vote
1
answer
48
views
For Loop - Failing to Iterate Over Elements
Issue: The for loop for this function is not iterating the over all elements. Its stopping at 1. I used some diagnostic print statements to count the number of loops and its stopping at 1. I have ...
1
vote
1
answer
53
views
How many iterations of a complex duration of time exists between a start date and end date?
For example, I'm using the moment.js library. You can specify a duration as follows : {years:1,months:1,weeks:1,days:1,hours:1,minutes:1,seconds:1}. This duration of time is subjective based on the ...
0
votes
0
answers
33
views
How to apply logical functions on all rows of a data table and not just the displayed rows?
I am facing an issue with understanding DataTable or JavaScript in general, if you could point me in the right direction I would be very grateful.
I am simply trying to apply the ...
1
vote
1
answer
36
views
Iterative tree parsing in Rust
Suppose we have a tree:
#[derive(Default, Debug, PartialEq, Eq)]
struct Tree {
children: Vec<Tree>,
}
And we want to build it from a list of bools where true is like an open tag and false ...
0
votes
1
answer
56
views
How to convert a Result into an Option inside iterator chain?
I've written this:
/* Turn a Vec<Vec<u8>> into a Vec<String>, without re-allocating the inner bytes. */
let lines: Vec<String> = u8_lines.into_iter()
....
1
vote
2
answers
84
views
Issues related to Gamma Regression
I want to derive coefficients of Gamma regression by iterated reweighted method (manually). When I run this code with out for{} loop it works properly but with loop it produce NaN. My code is:
n<-...
0
votes
1
answer
20
views
Adding a column in python based on multiple iterating conditions or looping
I'd like to create an extra column in python either using Pandas or Numpy based on iterating conditions ( I think that's the way to do it). ** If any value is "False" and with the same IDxx, ...
0
votes
2
answers
51
views
Select certain elements from a list with a loop and condition
I have a list similar to this one below, but much larger.
mylist = [' 12345678912 ST',
' Halterung für Fortlüfterhaube',
' ...
1
vote
2
answers
102
views
Add multiple columns and values to a pandas dataframe
I will ask my question with a small dataframe, but the real one is 1000s of lines.
ID Name #Required
123 New York 5
234 Boston 6
345 Miami 2
345 Dallas 7
I need the to the number of ...
1
vote
2
answers
30
views
How to take a point (xn, yn) in the plane and maps it to a new point?
I tried to use the loop method but the program stuck.
function getPoints() {
var x, y;
for (
x = 1, y = 2, a = 1.4, b = 0.3;
x < 10, y < 10;
x = 1 - a * x ** 2 + y, y = b * x
)...
0
votes
1
answer
38
views
Getting no output on console for big iteration without any error message
int main() {
int naturalNumber = 2;
int divider = 0;
int rest = 1;
long long int sumOfPrimes = 0;
while (naturalNumber <= 2000000) {
divider = naturalNumber;
...
0
votes
1
answer
51
views
Any generalized formula for the number of times "Anjali" will be printed? [closed]
#include <stdio.h>
int main(int argc, const char *argv[])
{
int n;
printf("Input a number: ");
scanf("%d", &n);
for (int i = 1; i <= n; i *= 3)
...