time

Numpy: Single loop vectorized code slow compared to two loop iteration

▼魔方 西西 提交于 2020-01-06 21:07:21
问题 The following codes iterates over each element of two array to compute pairwise euclidean distance. def compute_distances_two_loops(X, Y): num_test = X.shape[0] num_train = Y.shape[0] dists = np.zeros((num_test, num_train)) for i in range(num_test): for j in range(num_train): dists[i][j] = np.sqrt(np.sum((X[i] - Y[j])**2)) return dists The following code serves the same purpose but with single loop. def compute_distances_one_loop(X, Y): num_test = X.shape[0] num_train = Y.shape[0] dists = np

javascript: evaluate if given hour is between two hours

别来无恙 提交于 2020-01-06 20:04:03
问题 So there's plenty of examples on how to calculate the time between two dates. But in my case, I have a date X. Let's say it's today. X has a time associate to it, e.g. 08:00 (Or what I get back from .getHours() ) I need to know if the hours of X are between a start hour (say "07:00") and an end hour (say "12:00") X will be always retrieved via getHours() The start and end hour of the range have a fixed format (e.g. "07:00" and "12:00") Performance is an issue, so whatever performs better is

javascript: evaluate if given hour is between two hours

核能气质少年 提交于 2020-01-06 20:03:22
问题 So there's plenty of examples on how to calculate the time between two dates. But in my case, I have a date X. Let's say it's today. X has a time associate to it, e.g. 08:00 (Or what I get back from .getHours() ) I need to know if the hours of X are between a start hour (say "07:00") and an end hour (say "12:00") X will be always retrieved via getHours() The start and end hour of the range have a fixed format (e.g. "07:00" and "12:00") Performance is an issue, so whatever performs better is

Fastest way to calculate time differences in C#?

谁说我不能喝 提交于 2020-01-06 19:42:29
问题 It seems like there are a lot of ways to calculate time spans in c#. I am wondering which one is fastest and by that I simply means requires the least amount of processing. Let me throw out an example to illustrate exactly what I am trying to do. private const int timeBetweenEvents = 250; //delay ms DateTime nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0, 0, timeBetweenEvents)); ... while(true) { if (DateTime.Now > nextUpdate) { // do something nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0

How to get a cookie in php without refreshing the page?

前提是你 提交于 2020-01-06 19:00:43
问题 I currently have this code and two problems: I get the users timezone with Javascript and post it to the timezone.php via ajax, which sets a cookie with the users time. If the cookie is not set, say on first visit, the page would have to be refreshed in order to show the cookie value. I'm doing this with javascript at the moment, but there has to be another way. Also, since the page refreshes if there is no cookie, users with cookies disabled would get a refresh loop. Any suggestions on how

Plotting the frequency of string matches over time in R

空扰寡人 提交于 2020-01-06 18:37:10
问题 I've compiled a corpus of tweets sent over the past few months or so, which looks something like this (the actual corpus has a lot more columns and obviously a lot more rows, but you get the idea) id when time day month year handle what UK1.1 Sat Feb 20 2016 12:34:02 20 2 2016 dave Great goal by #lfc UK1.2 Sat Feb 20 2016 15:12:42 20 2 2016 john Can't wait for the weekend UK1.3 Sat Mar 01 2016 12:09:21 1 3 2016 smith Generic boring tweet Now what I'd like to do in R is, using grep for string

Accessing stdout when using “time” in python subproces

大城市里の小女人 提交于 2020-01-06 18:05:32
问题 I have been doing some manual benchmark tests in my shell using the time command. I would like to scale my benchmarks by writing a python script that both automates the tests and affords me access to the time data so that I can record it in the format of my choosing (likely a csv). I see there is the timeit module, but that seems like it is more for benchmarking python code, where what I am trying to benchmark here are programs run in the command line. This is what I have been doing manually:

sql select values on Continuous period of time

心已入冬 提交于 2020-01-06 17:56:19
问题 I have a table with below structure: id INT, order_id INT, datex DATE, timex TIME For example I want to select count of order ID's from 2017-10-24 to 2017-10-26 in specific periods of time. Like 2:0:0 - 4:0:0 , 4:0:0 - 6:0:0 etc and make a result like below: period | ordersID's 2:0:0 - 4:0:0 | 5 4:0:0 - 6:0:0 | 8 Can I do this by just a query or I should use other ways? 回答1: First thing is your time periods are overlapping. It is not clear that if orders occur at 4 what period they should

SSRS Format seconds as time (negative seconds)

时间秒杀一切 提交于 2020-01-06 17:43:06
问题 I have a column with integers: TotalSec that has seconds. It can be 0, negative or positive. I have to format these seconds in a report. But cant get something working for the negative seconds. My logic: For 0 = Nothing, For Positive format as HH:mm:ss For Negative - ABS the value then format as -HH:mm:ss =IIF(SUM(Fields!TotalSec.Value)=0, Nothing, IiF(SUM(Fields!TotalSec.Value)>0, Format(DateAdd("s",SUM(Fields!TotalSec.Value), "00:00:00"), "HH:mm:ss"), "-" & Format(DateAdd("s",ABS(SUM(Fields

Python custom datetime(?) format handling

回眸只為那壹抹淺笑 提交于 2020-01-06 17:09:35
问题 Let's say i have a string representing a time with number of day of the week: For example '52300', which means 5th day of week(Friday), 23 Hours 00 Minutes. How do i parse it to time or datetime object to add a timedelta(hours=3) and get it back to this strange format? Expected output is '60200' string. I have tried: tow_str = '52300' tow = datetime.datetime.strptime(tow_str, "%w%H%M") + datetime.timedelta(hours=3) print(tow.strftime("%w%H%M")) which returns '20200' instead of '60200' 回答1: