for-loop

For loop over sequence of large numbers in Bash [duplicate]

浪尽此生 提交于 2021-02-08 06:04:33
问题 This question already has answers here : Bash command line and input limit (3 answers) Closed 2 years ago . In a Bash script I am using a simple for loop, that looks like: for i in $(seq 1 1 500); do echo $i done This for loop works fine. However, when I would like to use a sequence of larger numbers (e.g. 10^8 to 10^12), the loop won't seem to start. for i in $(seq 100000000 1 1000000000000); do echo $i done I cannot imagine, that these numbers are too large to handle. So my question: am I

Checking membership in an array without for loop in matlab

邮差的信 提交于 2021-02-07 20:31:51
问题 I want to simplify this code to working without for loop. for i=1:N for j=1:N if ismember(j,A) PID(i,i)=TFP(i,j)+ PID(i,i); end end end in which A is a matrix that contains some labels. I previously stored TFP in the form of N*N sparse double. So, I came up with the following solution but I couldn't find a way to implement membership condition (Specified by ?) in that. PID = sum(TFP).*(?); Can it be implemented without a loop? 回答1: Your ismember(j,A) is equivalent of just using the values of

Checking membership in an array without for loop in matlab

给你一囗甜甜゛ 提交于 2021-02-07 20:30:33
问题 I want to simplify this code to working without for loop. for i=1:N for j=1:N if ismember(j,A) PID(i,i)=TFP(i,j)+ PID(i,i); end end end in which A is a matrix that contains some labels. I previously stored TFP in the form of N*N sparse double. So, I came up with the following solution but I couldn't find a way to implement membership condition (Specified by ?) in that. PID = sum(TFP).*(?); Can it be implemented without a loop? 回答1: Your ismember(j,A) is equivalent of just using the values of

How do I use variables in a postgresql function for loop query

半世苍凉 提交于 2021-02-07 18:32:06
问题 I have a rather complicated function in postgresql (Version 9.4.4) that I need a bit of help with. I have a loop (with lots of work below) declared like this inside of my function: CREATE OR REPLACE function getRSI( psymbol varchar, pstarttime timestamp with time zone, pendtime timestamp with time zone, pduration double precision, ptable varchar ) RETURNS SETOF rsi AS $BODY$ declare row_data record; -- some variables begin FOR row_data IN SELECT datetime, value FROM "4" WHERE symbol = 'AAPL'

How do I use variables in a postgresql function for loop query

拈花ヽ惹草 提交于 2021-02-07 18:32:00
问题 I have a rather complicated function in postgresql (Version 9.4.4) that I need a bit of help with. I have a loop (with lots of work below) declared like this inside of my function: CREATE OR REPLACE function getRSI( psymbol varchar, pstarttime timestamp with time zone, pendtime timestamp with time zone, pduration double precision, ptable varchar ) RETURNS SETOF rsi AS $BODY$ declare row_data record; -- some variables begin FOR row_data IN SELECT datetime, value FROM "4" WHERE symbol = 'AAPL'

Vectorize a 6 for loop cumulative sum in python

馋奶兔 提交于 2021-02-07 14:57:54
问题 The mathematical problem is: The expression within the sums is actually much more complex than the one above, but this is for a minimal working example to not over-complicate things. I have written this in Python using 6 nested for loops and as expected it performs very badly (the true form performs badly and needs evaluating millions of times), even with help from Numba, Cython and friends. Here it is written using nested for loops and a cumulative sum: import numpy as np def func1(a,b,c,d):

How to correctly use group_by() and summarise() in a For loop in R

百般思念 提交于 2021-02-07 13:34:55
问题 I'm trying to calculate some summary information to help me check for outliers in different groups in a dataset. I can get the sort of output I want using dplyr::group_by() and dplyr::summarise() - a dataframe with summary information for each group for a given variable. Something like this: Sepal.Length_outlier_check <- iris %>% dplyr::group_by(Species) %>% dplyr::summarise(min = min(Sepal.Length, na.rm = TRUE), max = max(Sepal.Length, na.rm = TRUE), median = median(Sepal.Length, na.rm =

Restart current iteration in 'for' loop java

我们两清 提交于 2021-02-07 12:25:50
问题 I have a for loop that asks the user to input a number and then does something with it 10 times I want a check built in that, if the user enters a non accepted input, the loop should restart its current iteration For example if the user enters something wrong in round 3, round 3 should be restarted. How do i do that? is there something like a REDO statement in java? 回答1: something like this ? for(int i=0; i<10; i++){ if(input wrong){ i=i-1; } } 回答2: You have a couple of choices here. Continue

Restart current iteration in 'for' loop java

我的未来我决定 提交于 2021-02-07 12:25:14
问题 I have a for loop that asks the user to input a number and then does something with it 10 times I want a check built in that, if the user enters a non accepted input, the loop should restart its current iteration For example if the user enters something wrong in round 3, round 3 should be restarted. How do i do that? is there something like a REDO statement in java? 回答1: something like this ? for(int i=0; i<10; i++){ if(input wrong){ i=i-1; } } 回答2: You have a couple of choices here. Continue

r for loop for regression lm(y~x)

情到浓时终转凉″ 提交于 2021-02-07 08:47:48
问题 Example: df <- data.frame(A=1:5, B=2:6, C=3:7,D=4:8,E=5:9,F=6:10) I want make a regression loop lm(y,x) using like y the col 1 and 2 and like x the rest of the cols. my idea: lmf <- function (y,x) { f <- lm(y ~ x, data=df) cbind(summary(f)$r.squared,summary(f)$coefficients) } for(y in 1:3) { R<- apply(df[,3:6], 2, lmf(y,x)); R } error: Error in model.frame.default(formula = y ~ x, data = df, drop.unused.levels = TRUE) : variable lengths differ (found for 'x') I give this example very small