Questions tagged [processing-efficiency]

622 questions
2
votes
0 answers

Constructing sparse matrix is very slow in Julia

I am trying to create a sparse matrix in Julia using theses variables: row, col and val. The size of each is 73141861 which will finally creates a sparse matrix with (6554063, 6554063) dimension. I use the following function: AS = sparse(row, col,…
Akon
  • 113
  • 10
2
votes
2 answers

How obtain a number what is repeated a n times?

I have a file with a lot of numbers: 0.98 0.23 0.10 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 10.3 11.9 0.56 ... I want to print the number of line where the number 0 is repeated 10 consecutive times (as minimum). Consdering the above input, the…
Hdez
  • 151
  • 7
2
votes
2 answers

time complexity of if else statement c#

Which of the following two is more efficient from a processing / time complexity point - sorry just trying to get my head round time complexity and potential impact on computer processing time: Option 1 if (condition1) { function1(); …
2
votes
0 answers

Creating an efficient local search technique in Python for Latin Squares

I am basically needing to create a local search technique using the cost function. I need to create a new function that randomly swaps the original solution in the latin square, then calculates the cost and if it is better than the original…
JamieNorth
  • 21
  • 2
2
votes
3 answers

Effecient way to repeat y/n question in python

I am looking for a way to implement a "press Y to continue, N to cancel" prompt. My current way to implement it is Prompt = None # Loop until the user inputs a valid answer while Prompt not in ("yes", "y", "n", "no"): Prompt = input("Do you…
user12513149
2
votes
4 answers

Python: Removing list duplicates based on first 2 inner list values

Question: I have a list in the following format: x = [["hello",0,5], ["hi",0,6], ["hello",0,8], ["hello",1,1]] The algorithm: Combine all inner lists with the same starting 2 values, the third value doesn't have to be the same to combine…
Rlz
  • 1,649
  • 2
  • 13
  • 36
2
votes
1 answer

Inserting into a linked list in alphabetical order efficiently

I am inserting items from a class I've created into a linked list, but I must find the correct index point to insert them to (so the items are in alphabetical order) before I add it. I have some working code but it's ridiculously inefficient,…
2
votes
1 answer

Compare two lists of different types using HashMap

I have two classes: public class AClass{ String name; int id; int total; } public class BClass{ String batchName; int id; } Now I have two lists: List aLst; List bLst; Between these two list i need to check if…
2
votes
2 answers

Most efficient way to hash each line of a text file?

I'm currently writing a Bash script which hashes each line of a text file and outputs it into a new file with the format hash:orginalword. The script I have at the moment to do this is: cat $originalfile | while read -r line; do hash="$(printf…
Tom
  • 159
  • 1
  • 7
2
votes
1 answer

Efficiently extract a patch from image and lable

I have a segmentation project. I have images and labels, which holds ground truth for the segmentation. The images are large, and contains a lot of "empty" areas. I want to cut patches from image and label, so that the patch will have non-zero…
Naomi Fridman
  • 2,095
  • 2
  • 25
  • 36
2
votes
0 answers

Assign value at multiple index in ruby array at once

I have an array of 10_000 elements or more, and I have got a bunch of random numbers, for example, say [10,20, 45, 15, 99, 682, 100]. I know that I can loop over array and access or set some value at these indexes. My questions is that can I assign…
Sachin Singh
  • 7,107
  • 6
  • 40
  • 80
2
votes
1 answer

Algorithm to get all the individual areas from a figure

As input we only have a set of segments, here is an example : [AB] = [(0, 0), (0, 4)] ; [BC] = [(0, 4), (2, 6)] [CD] = [(2, 6), (4, 0)] ; [DA] = [(4, 0), (0, 0)] [CE] = [(2, 6), (5, 6)] ; [EF] = [(5, 6), (5, 3)] [FG] = [(5, 3),…
Cinn
  • 4,281
  • 2
  • 20
  • 32
2
votes
1 answer

Python: how can this code be made to run faster

I am new to Python and I am slowly learning via Codewars. I know this is potentially against the rules but I have an efficiency question. You are given a list of integers ls = [100, 76, 56, 44, 89, 73, 68, 56, 64, 123, 2333, 144, 50, 132, 123, 34,…
GhostRider
  • 2,109
  • 7
  • 35
  • 53
2
votes
2 answers

C++ vector element erase versus new vector creation

I'm working with a vector of elements that need to be selected at random and effectively removed until either either a condition is met, or until all the elements have been selected. However, they won't actually be removed until some later stage in…
2
votes
1 answer

In what order should you list CSS properties for greatest speed?

Let's take some CSS properties and place them randomly in our CSS file: outline pseudo-elements Color Properties Background and Border Properties Box Properties Flexible Box Layout Text Properties Text Decoration Properties Font…
Chris P
  • 63
  • 8