coding-efficiency

How to efficiently calculate distance between GPS points in one dataset and GPS points in another data set using data.table

霸气de小男生 提交于 2019-12-11 06:09:46
问题 I am facing a coding (optimization) problem in R. I have a long data set with GPS coordinates (lon, lat, timestamp) and for every row I need to check whether the location is near a bus stop. I have a .csv file with all the bus stops (in the Netherlands). The GPS coordinates file is millions of entries long, but could be split if necessary. The bus stop dataset is around 5500 entries long. Using the code and tips given on, inter alia, these pages: 1) How to efficiently calculate distance

Excel VBA updating dates efficiently with non-unique string values and boolean data

北城余情 提交于 2019-12-11 04:26:21
问题 I am looking for a way in VBA for Excel that's quicker than arrays for updating dates from data. I have tried using scripting.dictionary but got stuck. Sample data and current code that works are below. Values for serial are non-unique. Hence currently thinking that these need to be looped over twice for considering each row. The objective of the code is to set dates1 to be value of dates2 when there is a match on serial and value of boolean1 is 1 , then to output this back to the sheet.

Computing the nth Fibonacci number using linear recursion [duplicate]

吃可爱长大的小学妹 提交于 2019-12-10 11:43:10
问题 This question already has answers here : Java arrays printing out weird numbers and text [duplicate] (10 answers) Closed last month . I have tried binary recursion to find the nth Fibonacci number (or the whole Fibonacci series by using a for loop in main() ) but according to Data Structures and Algorithms in Java (6th Edition) by Michael T. Goodrich; it is a terribly inefficient method as it requires an exponential number of calls to the method. An efficient recursion technique is linear

R: efficiently computing summaries of value-subsets whose contents are determined by the relation between two variables

大兔子大兔子 提交于 2019-12-08 02:46:02
问题 I have two tables, A and B . For each row of table A , I want to get some summary statistics for B$value where the value of B$location is within 100 of A$location . I've accomplished this using the for-loop below, but this is a slow solution that works well when the tables are small but I would like to scale up to a table A which is thousands of rows and a table B which is nearly a millions of rows. Any ideas of how to achieve this? Thanks in advance! The for-loop: for (i in 1:nrow(A)) {

When does vectorization is a better or worse solution than a loop? [duplicate]

醉酒当歌 提交于 2019-12-06 05:34:57
This question already has answers here : 'for' loop vs vectorization in MATLAB (5 answers) Closed 3 months ago . In Matlab, I am trying to vectorise my code to improve the simulation time. However, the result I got was that I deteriorated the overall efficiency. To understand the phenomenon I created 3 distinct functions that does the same thing but with different approach : The main file : clc, clear, n = 10000; Value = cumsum(ones(1,n)); NbLoop = 10000; time01 = zeros(1,NbLoop); time02 = zeros(1,NbLoop); time03 = zeros(1,NbLoop); for test = 1 : NbLoop tic vector1 = function01(n,Value);

Better way in Python to count string in another string

断了今生、忘了曾经 提交于 2019-12-01 11:17:23
This code works, but reading posts on here I get the impression it is probably not a very "Pythonic" solution. Is there a better more efficient way to solve this specific problem: What this code does: it counts instances of one string found in another and return the count. It raises an error in case the user tries to pass in an empty string. The version of the code I came up with but wondering if there is a better more efficient more "Pythonic" way to do this: def count_string(raw_string, string_to_count): if len(string_to_count) == 0: raise ValueError("The length of string_to_count should not

What is the most efficient approach to compose a string of length N where random characters are selected from a-f, 0-9

守給你的承諾、 提交于 2019-11-28 03:13:42
问题 The requirement is to determine the most efficient approach to render a string, for example, "#1a2b3c" , where "1a2b3c" are randomly selected from the set "abcdef0123456789" or ["a", "b", "c", "d", "e", "f", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] For the uniformity of comparing results, the string .length should be precisely 7 , as indicated at example above. The number of iterations to determine resulting time of procedure should be 10000 as used in the code below. We can commence