417 questions
1
vote
0
answers
49
views
Pine script variable definition with var vs without var ,performance?
In Pine script version 6, we can define a variable with var and without var.
Like this sample:
var float Number1 = 0.0
and
float Number1 = 0.0
If this variable does not need the value of the ...
0
votes
0
answers
29
views
What is the least redundant way I can write partially overlapping sets of conditions in Python?
I have a code where many combinations of conditions (some parts of which are repeated) lead to the same outcome. For example:
if (A and Y and a) or (B and Y and b) or (C and c):
run()
I feel ...
0
votes
2
answers
477
views
is there a quicker way to save csv files as polars dataframes than using list comprehension?
I have 2 folders each containing 1507 csv files, i am using the following code to save each file as a polars dataframe using list comprehension:
bdsim=[pl.read_csv(x, schema_overrides = {"X0.6&...
1
vote
0
answers
87
views
Clean short code to show days since button was clicked
There are various buttons in my C# winform and for each button press an action is associated with it. I currently have code where when the button is clicked I record the date the button was clicked, ...
1
vote
0
answers
49
views
Optimizing Batch Inserts for Improved Efficiency in Flask SQLAlchemy
I am trying to insert 60 to 70 rows at once in a SQL Server table. Currently, I have a function to do it but it is taking almost 15 seconds to complete the task. It would not be a problem if it was ...
-1
votes
1
answer
95
views
Is there any better way to write this piece of code? [duplicate]
I am a beginner in this, I was curious if i can write the below code
more efficiently.
I can't use loops or conditional statements, just logical operators.
double a = Double.parseDouble(args[0]...
0
votes
0
answers
29
views
SQL - Is there a shorthand to refer to columns with same prefix and incrementing suffix (like, var1, var2, var3...) in a where statement?
I'm looking to do something like this:
create or replace table patients as
select distinct id
from dataset
where value in (var1:var30)
;
I could make a temp table that contains just the variable ...
0
votes
0
answers
52
views
How can I rewrite a for loop with multiple (nested) if statements to get faster runtimes?
My code currently looks like:
for j in range(len(destined)):
if destined[j] == 1:
if den[j,i+1] == 0:
is_dense = np.hstack((is_dense, j))
elif den[j,i+1]...
1
vote
1
answer
268
views
Fastest way to do repeated element wise matrix multiplication in MATLAB?
Given a matrix A, I need to multiply with another constant vector B, N times (N > 1 million). The size of A is 9000x1 and B is 9000x1000.
The code is currently evaluated in the following way:
for i=...
1
vote
1
answer
86
views
Efficient way to count number of Set! in a table
I am programming the game Set! which consist of finding a valid set of three cards in a table of twelve cards.
Each card has a unique combination of four characteristics:
-Shape(Oval, Diamond, peanut)
...
0
votes
1
answer
60
views
Is it efficient to access/update an array using stored in site options using get_option and update_option in a loop?
I have an array stored in the site options in WordPress which will potentially have 3000 email addresses in it. Every night I need to process this list with some checks on those email addresses and I'...
0
votes
2
answers
103
views
C# Commutativity in if statements [closed]
Is there a way to essentially write "and vice versa" in an if statement without writing the same code again but with "||"?
if (currentDirection == 1 && nextDirection == 2)
...
0
votes
1
answer
42
views
Pandas Dataframe with dictionary cells | accumulate by values | inefficient apply method
Given:
Sample Pandas Dataframe with dictionaries in each cell:
user_token_df = pd.DataFrame(
{
"usr": ["u1", "u2", "u3", "u4", "u7"...
0
votes
2
answers
502
views
Row-level calculations within a windows function?
I'm working on this problem from LeetCode.com:
Column Name
Type
machine_id
int
process_id
int
activity_type
enum
timestamp
float
The table shows the user activities for a factory website.
(machine_id, ...
-1
votes
2
answers
106
views
How to combine comparisons of the same variable in if statements
if (i != 0 && i != 15 && i != 20)
{
...
}
For the above code snippet, how can I combine all the conditions so I won't have to use multiple comparison operators?
1
vote
1
answer
64
views
How to edit multiple variables inside a structure in C
typedef struct
{
string color;
int age;
}Dog;
int main(void)
{
Dog cookie = ("brown", 6);
cookie.color = "blue";
cookie.age = 12;
}
Hello, I'd like to know if ...
0
votes
0
answers
41
views
Inefficient programming with jdbc and mysql
I am currently programming an application, that connnects to a mysql database and reads, inserts and changes data in it. I am coding in Kotlin and use the JDBC Driver. My problem is, that for every ...
0
votes
1
answer
42
views
pandas goupby method slow and inefficient for sum()
Given:
A synthetic dataset in pandas DataFrame format users vs. tokens, generated via the following helper function:
import numpy as np
import pandas as pd
import string
import random
def get_df(...
0
votes
1
answer
913
views
What is the most efficient way to remove tracking, marketing, etc query parameters from a URL in .NET? [closed]
So, I have an issue. I need to try and get as "clean" or a URL as possible; meaning removing unnecessary query parameters from an URL. I realize that this would be close to impossible to do, ...
1
vote
4
answers
145
views
What is the fastest R way to generate random variates of the Bates distribution?
It is a simple task to get random numbers of the Bates distribution. I need 1 million averages to run 10k times:
bates1 = replicate(10000, mean(runif(1e+06,1,5)))
summary(bates1)
I waited forever to ...
-1
votes
1
answer
112
views
What is the cost function for this algorithm?
my question is in the title.
After hours of thinking and looking up sites on google i came to the conclusion that i'm not quite sure how to solve this problem or if it is correct. Maybe you guys could ...
1
vote
2
answers
523
views
R: Grouped summary statistics of multiple variables conditional on other different columns
I am trying to get grouped summary statistics of multiple variables conditional on other different columns. For example, I have three total difference variables (n.diff.total) and three variables ...
0
votes
2
answers
44
views
How to code it in a more efficient way : delete multiple row with a very complex condition in R
Below is a sample of a large data set from which I want to delete quadrats (Qm) numbered greater than than 3 in parcels (PARCELLE) 1, 3, 4, and 8.
FIELD SECTOR PARCELLE Qm Total
North A 1 ...
-1
votes
2
answers
71
views
How to efficiently overwrite a variable value if present in configuration dictionary?
I have a simple piece of code that works, but I'd like to know if I can make it more Pythonic by using the dict.get() method.
chunk_size = 100000
if "chunk_size" in self.conf["...
0
votes
2
answers
347
views
Use variable in 'document.getElementById("…")' for IDs to reduce duplicated code
I have written a dice roller utility for a tabletop RPG in JavaScript.
Before I add more functionality to it, I would like to simplify the code by simplifying functions to remove unnecessary code.
...
2
votes
1
answer
65
views
Identifying and counting "correct" letters in a comma delimited string in R
In this problem, I am trying to "score" a task from a computer administered questionnaire, where each person is asked to type 5, 3-letter words into a text box. The result in the data.frame ...
0
votes
1
answer
1k
views
Is it possible to show a different icon on taskbar for a Windows application instance ran with a different user account?
I run 2 Microsoft Edge browser instances for work, 1 for normal use and the other for AWS Console SAML login. I often mix them up.
The latter is started with "runas /u: 'C:\ \msedge.exe'".
...
1
vote
1
answer
951
views
Why is this O(sqrt(n))?
Can anyone explain why this is O(sqrt(n))? Is the best way to approach this by putting numbers to it?
i:=1
p:=0
for (p<n) do
p = p+i
i+=1
Picture Here
I thought it was O(n), but if I put n =...
0
votes
1
answer
39
views
R: Improving processing time for a set of codes
Question:
How can I improve the processing time of the following code?
Goal description:
I have the following example dataset in which each observation contains
ids of two individuals (the primary ...
1
vote
2
answers
107
views
R: Improving efficiency of getting sum of differences in R
Purpose:
past vector is the set of o3.cpts found in the past period.
current vector is the set of o3.cpts found in the current period.
Each o3.cpt has a set of numbers that are associated with the ...
0
votes
2
answers
240
views
Delete rows with overlapping intervals efficiently
Consider the following DataFrame
>>> df
Start End Tiebreak
0 1 6 0.376600
1 5 7 0.050042
2 15 20 0.628266
3 10 15 0.984022
4 11 12 0.909033
5 ...
1
vote
1
answer
65
views
Assessing & improving the runtime efficiency for loading a large number of CSV datasets into R and assigning all of them to a list object
All of the code included in this question can be found in the 'LASSO code(Version for Antony)' script in the GitHub Repository for this project.
This is all part of a research project with a ...
0
votes
0
answers
105
views
Difference between pandas functions: df.assign() vs df.reset_index()
So lets say I have a DataFrame:
stuff temp
id
1 3 20.0
1 6 20.1
1 7 21.4
2 1 30.2
2 3 0.0
2 2 34.0
3 7 0.0
3 6 0.0
3 ...
5
votes
1
answer
631
views
How can I generate prime palindromes in a given range without complete searching it and using a check function?
I have seen previous solutions to this problem, but it is all complete search with a check function and not fast enough for me.
I am working on a C++ program trying to generate all prime palindromes ...
0
votes
0
answers
29
views
Should I create core classes for better quality Flutter code?
I'm trying to improve myself to write better quality code. However, I have a question. For example, does it make sense to create an appbar class like the one below and call that code where I need it? ...
0
votes
1
answer
51
views
How to sum a frequency table into smaller intervals without loops?
I would like to sum a frequency table into a more compact frequency table by filtering by a variable and certain intervals without using loops and manually creating most of the data frame.
What I'm ...
1
vote
1
answer
374
views
Which is faster ?Multiple Conditions in one IF statement or switch case with multiple IF statements
I came to a point where I needed to check a condition and proceed with another condition if its true for many times.
Here I'm using fromNS string which has the base of number (like - binary, decimal, ...
-1
votes
2
answers
200
views
How can I make my recursion program to output factorial of a number more efficient?
I have made a program which outputs the factorial of a number by calling the function: factorial() which uses recursion to calculate and return the value. I have also included a loop to break the ...
1
vote
4
answers
162
views
Is there way to optimize the speed for changing values in a >2 million row data frame?
I have got a tibble of more than 2 million rows. One of the columns size is a value using M to represent million, k to represent thousand; it also has some <NA> values. The column type is ...
1
vote
0
answers
1k
views
Fastest and Most Efficient way to check for duplicates in a javascript array [duplicate]
I am writing a javascript function that takes a nested array and returns the numbers that occurs more than once in that array.
I believe my function is accurate (meaning that it passes their "...
0
votes
0
answers
143
views
The fastest and most efficient way to get repeated numbers in a nested array [duplicate]
I know how to do this combining a lot of if...else statements but I need a faster and more efficient way.
I need a function that will run through a nested array and return the numbers that occur more ...
0
votes
0
answers
29
views
Cleaning up MONTHDAY selector for an RRULE generator
Okay, so I'm trying to update some old js/html/jquery code for my work website. I want to modify a section of code which I'm pretty sure is written with horrible inefficiency, but I'm too dumb to know ...
1
vote
0
answers
61
views
efficiency in 2 different scenario of code structure on mql4 Expert Advisor
Hi I have EA with code structure like this,
void OnTick()
{
resetCounterVar(); //there's for loop
CloseOrders(); //there's for loop
UpdateAllOpenOrders(); //there's for loop
SetSLTP(); //...
0
votes
2
answers
46
views
Is there any more efficient way to code my php $_GET multiple URL parameter?
Hi i want to make some kind of filtering feature, so in my example there are the brand of the car and the type of the car and if both are exist i want the brand url parameter always in the front of ...
0
votes
2
answers
85
views
Efficiency question: how to compare two huge nested lists and make changes based on criteria
I want to compare two huge identical nested lists and by iterating over both of them. I'm looking for nested lists in where list_a[0] is equal to list_b[1]. In that case I want to merge those lists (...
0
votes
1
answer
214
views
MATLAB find on multiple columns to multiple column result
Setup
I have an array of captured data. The data may be captured on just 1 device or up to a dozen devices, with each device being a column in the array. I have a prior statement which I execute on ...
0
votes
0
answers
94
views
Find timedeltas in dataframe
I have a pandas dataframe containing 400 individual measurements. Each mesurment is a time series composed of roughly 1000 rows. The whole dataframe therefore contains roughly 400.000 rows. The index ...
0
votes
1
answer
46
views
How can I make it so that I can add special attacks in the editor instead of repeatedly adding for loops?
I have this code that lets me handle button combinations in Unity:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputBufferScriptTest: MonoBehaviour {
...
-1
votes
1
answer
54
views
How can I make one piece of code for several structs?
I have 4 structs:
Computer,
Home,
Car,
Ship
I declared:
1. An array that can hold up to 5 types of computers.
2. An array that can hold up to 20 houses, each can have one computer.
3. An array that ...
2
votes
1
answer
176
views
R improve loop efficiency: Operating on columns that correspond to rows in a second dataframe
I have two data frames:
dat <- data.frame(Digits_Lower = 1:5,
Digits_Upper = 6:10,
random = 20:24)
dat
#> Digits_Lower Digits_Upper random
#> 1 ...