counting

Inconsistency of na.action between xtabs and aggregate in R

旧时模样 提交于 2020-06-27 09:15:08
问题 I have the following data.frame: x <- data.frame(A = c("Y", "Y", "Z", NA), B = c(NA, TRUE, FALSE, TRUE), C = c(TRUE, TRUE, NA, FALSE)) And I need to compute the following table with xtabs : A B C Y 1 2 Z 0 0 <NA> 1 0 I was told to use na.action = NULL, which indeed returns the table I need: xtabs(formula = cbind(B, C) ~ A, data = x, addNA = TRUE, na.action = NULL) A B C Y 1 2 Z 0 0 <NA> 1 0 However, na.action = na.pass returns a different table: xtabs(formula = cbind(B, C) ~ A, data = x,

Moviepy's ImageSequenceClip() reads PNGs wrongly like 0, 10, 100 instead of traditional counting

为君一笑 提交于 2020-06-17 02:50:27
问题 So I have this for-loop that creates a photo of each earthquake and names them earthquake0, earthquake1, earthquake2, and so on. plt.savefig("exports\earthquake{0}.png".format(i)) To convert these images to GIF, I use this image_list='exports' my_clip = ImageSequenceClip(image_list, fps=0.75) my_clip.write_gif('eqph_gif.gif') However, ImageSequenceClip() reads the files like earthquake0.png, earthquake10.png, earthquake100.png. How do I make my code read the photos traditionally like 0, 1, 2,

How to create a date counter ? i tried it using reduce function

我只是一个虾纸丫 提交于 2020-05-17 07:45:09
问题 using id, billStatus and tDate need to make a daycounter which counts date of days leads are received. Example => for id:"1" 2 Billable against 8th of may AND 3 Billable for 9th of may than day counter will become => 1+1 = 2 Note: if I get 1 lead or 7 leads for a single day daycount will be 1 and increment the next day when there will be any new lead on a new day. data: [ { id: "1", billStatus: "Billable", tDate: "05/08/2020", dayCounter: 0 }, { id: "1", billStatus: "Billable", tDate: "05/08

线性排序:计数排序 Counting Sort 和 基数排序 Radix Sort

て烟熏妆下的殇ゞ 提交于 2020-03-22 00:04:12
3 月,跳不动了?>>> 基于比较的排序最好的时间复杂度为O(N*lgN),证明如下: 每种基于比较的排序都能够使用决策树描述其排序过程,每个节点最多有2个子节点。 该决策树的树叶的最大值即为所有可能的排序结果之和,即N的阶乘N!。 决策树的高度h即为比较的次数,因为二叉树节点数最多为2^h,所以有N! <= 2^h, 根据斯特林公式可知: h >= lgN! >= lg(N/e)^N = N*lg(N/e) = N*lgN - N*lge 因此算法复杂度最好为: O(N*lgN - N*lge) = O(N*lgN) 如果要追求效率更高的排序算法,比如线性排序,就要使用其他的非基于比较的排序算法。 本文用C实现了两种线性排序算法,分别为计数排序Counting Sort 和 基数排序 Radix Sort。这两种算法的实现要求排序元素为整数。 计数排序包括两步:计数和分配。首先对每个元素出现的次数进行计数,然后设置前缀数组得知每个元素在完成排序的数组中的位置,最后依照前缀数组进行元素分配。 可以证明,计数排序的时间复杂度为O(k+n),其中k为元素最大值,n为元素个数。 计数排序简单实现如下: /* Counting Sort include two steps: * Countint and Distribution. */ void countingSort(int arr[

Count unique values per unique keys in python dictionary

早过忘川 提交于 2020-01-25 11:38:05
问题 I have dictionary like this: yahoo.com|98.136.48.100 yahoo.com|98.136.48.105 yahoo.com|98.136.48.110 yahoo.com|98.136.48.114 yahoo.com|98.136.48.66 yahoo.com|98.136.48.71 yahoo.com|98.136.48.73 yahoo.com|98.136.48.75 yahoo.net|98.136.48.100 g03.msg.vcs0|98.136.48.105 in which I have repetitive keys and values. And what I want is a final dictionary with unique keys (ips) and count of unique values (domains). I have laready below code: for dirpath, dirs, files in os.walk(path): for filename in

Consecutive values in array with periodic boundaries in Python

谁说我不能喝 提交于 2020-01-25 08:04:18
问题 I have some 2D-arrays filled with 0 and 1 : import numpy as np a = np.random.randint(2, size=(20, 20)) b = np.random.randint(2, size=(20, 20)) c = np.random.randint(2, size=(20, 20)) d = np.random.randint(2, size=(20, 20)) and I want to count the consecutive occurrence of the ones with periodic boundaries. That means (in 1D for clearness): [1 1 0 0 1 1 0 1 1 1] should give me 5 (last three elements + first two). The 2D-arrays should be compared/counted in the third (second if you start with 0

How to reference to previous matching record using arrayformula?

泪湿孤枕 提交于 2020-01-24 13:41:49
问题 I have a project spreadsheet, with project managers entering current progress status for each project for each month where there was some activity. So the columns A B and C are filled, I need to be able to figure out the column D using arrayformula. (note that there was no activity/record for "Project 1" in June 2019) I thought I would first need a helper column to find the date of the previous record for the project and then vlookup the date for the project and return the progress of that

How to convert a dictionary to a list of keys, with repeat counts given by the values?

两盒软妹~` 提交于 2020-01-20 04:23:05
问题 I need your help to solve a problem. I want to convert a dictionary d = {key1:value1, key2:value2} into list= [keys1, keys1, ... (value1 times), keys2, ... (value2 times)] without using a nested loop. Example: d1 = {4: 1, 3: 2, 12: 2} The code should produce the output: l = [4, 3, 3, 12, 12] This is what I have: for key, value in nums1.items(): temp = (str(key))*value nums2.append(int(temp)) print(nums2) Which gives: [4, 33, 1212] , but should give [4, 3, 3, 12, 12] . The complexity should be

Count repeating integers in an array

最后都变了- 提交于 2020-01-14 07:53:09
问题 If I have this vector: x = [1 1 1 1 1 2 2 2 3 4 4 6 6 6 6] I would like to get the position of each unique number according to itself. y = [1 2 3 4 5 1 2 3 1 1 2 1 2 3 4] At the moment I'm using: y = sum(triu(x==x.')) % MATLAB 2016b and above It's compact but obviously not memory efficient. For the pure beauty of MATLAB programming I would avoid using a loop. Do you have a better simple implementation ? Context: My final goal is to sort the vector x but with the constraint that a number that

How to apply the concept of counting occurrences on strings variables in C++

非 Y 不嫁゛ 提交于 2020-01-11 11:32:54
问题 following program ca calculate the frequency of ints in an array how to apply this concept on string variable because a string is also an array on the back end using namespace std; int counter[10]={0,0,0,0,0,0,0,0,0,0}; int arr [9][9],x; int main() { srand(time(NULL)); cout<<"enter the array \n"; for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ arr[i][j]=rand()%10; } } for(int i=0;i<9;i++){ for(int j=0;j<9;j++){ cout<<arr[i][j]<<" "; } cout<<endl; } for(int i=0;i<9;i++){ for(int j=0;j<9;j++){