counting

How to find all possible combinations of balls? [duplicate]

瘦欲@ 提交于 2019-12-24 22:45:09
问题 This question already has answers here : Generate a matrix containing all combinations of elements taken from n vectors (4 answers) Closed last month . I need to find all possible ways to combine k amount of balls from n types of balls. Let's say if there are 3 types of balls and I want to take 2, result I want is: 1 1 1 2 1 3 2 2 2 3 3 3 I am trying to do it with the following line: unique(nchoosek(repmat(1:n, 1, n), k), 'rows') I get: 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 How to do find all

Batch counting number of lines of text file without blank

早过忘川 提交于 2019-12-24 13:53:03
问题 I got two text files with different formats,let says i already have known there are 4 non-empty lines in the file,shown below (1st is valid, 2nd is invalid). AAA BBB CCC END (Blank line) (Blank line) AAA BBB (Blank line) CCC END Any "for loop" implementations/ways to distinguish 1st file has 4 non-empty lines which can tell it's valid and 2nd file has a extra blank line in the middle which can tell it's invalid. Because i got a for loop code which can count non-empty line number,applying that

Understanding how to count FLOPs

自闭症网瘾萝莉.ら 提交于 2019-12-24 12:59:25
问题 I am having a hard time grasping how to count FLOPs. One moment I think I get it, and the next it makes no sense to me. Some help explaining this would greatly be appreciated. I have looked at all other posts about this topic and none have completely explained in a programming language I am familiar with (I know some MATLAB and FORTRAN). Here is an example, from one of my books, of what I am trying to do. For the following piece of code, the total number of flops can be written as (n*(n-1)/2)

(Java) Counting letters in a sentence?

 ̄綄美尐妖づ 提交于 2019-12-24 10:44:56
问题 The following is my code: char[] array = new char[26] ; int index = 0 ; int letter = 0 ; int countA = 0 ; String sentence = "Once upon a time..." ; if(sentence.contains(".")) { String sentenceNoSpace = sentence.replace(" ", "").toLowerCase() ; String sentenceFinal = sentenceNoSpace.substring(0, sentenceNoSpace.indexOf(".")) ; char[] count = new char[sentenceFinal.length()] ; for (char c = 'a'; c <= 'z'; c++) { array[index++] = c ; for(int i = 0; i < sentenceFinal.length(); i++) { if

Counting how many times a value appeared

烂漫一生 提交于 2019-12-24 10:42:55
问题 I am using SELECT DISTINCT name FROM table to get a table with distinct names that appear in the column. How can i get an extra column returning the number of times that this specific name have appeared on the column? 回答1: select name, count(1) from table group by name; 来源: https://stackoverflow.com/questions/7437619/counting-how-many-times-a-value-appeared

Counting distinct items in XSLT independent of depth

假装没事ソ 提交于 2019-12-24 10:37:57
问题 If I run the following XSLT code: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:key name="kValueByVal" match="variable_name/@value" use="."/> <xsl:template match="assessment"> <xsl:for-each select=" /*/*/variable/attributes/variable_name/@value [generate-id() = generate-id(key('kValueByVal', .)[1]) ] "> <xsl:value-of select= "concat(., ' ', count(key('kValueByVal', .)), ' ')"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>

python: vectorized cumulative counting

半世苍凉 提交于 2019-12-24 09:58:21
问题 I have a numpy array and would like to count the number of occurences for each value, however, in a cumulative way in = [0, 1, 0, 1, 2, 3, 0, 0, 2, 1, 1, 3, 3, 0, ...] out = [0, 0, 1, 1, 0, 0, 2, 3, 1, 2, 3, 1, 2, 4, ...] I'm wondering if it is best to create a (sparse) matrix with ones at col = i and row = in[i] 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0 Then we could

How to count frequency of a element in numpy array?

北慕城南 提交于 2019-12-24 07:58:16
问题 I have a 3 D numpy array which contains elements with repetition. counterTraj.shape (13530, 1, 1 For example counterTraj contains such elements: I have shown few elements only: array([[[136.]], [[129.]], [[130.]], ..., [[103.]], [[102.]], [[101.]]]) ``` I need to find frequency of different element: Example: 136 count 5 (say), 101 count 12 (say). The array elements are not fixed and changes with input data. I try following: from collections import Counter Counter(counterTraj) Following error

Counting problem C#

谁说我不能喝 提交于 2019-12-24 03:24:06
问题 I've a bit of a problem. I'm adding numbers to ArrayList like 156, 340 (when it is TransferIn or Buy ) etc and then i remove them doing it like 156, 340 (when it's TransferOut , Sell ). Following solution works for that without a problem. The problem I have is that for some old data employees were entering sum's like 1500 instead of 500+400+100+500. How would I change it so that when there's Sell/TransferOut and there's no match inside ArrayList it should try to add multiple items from that

Find longest run of consecutive zeros for each user in dataframe

╄→尐↘猪︶ㄣ 提交于 2019-12-24 01:02:00
问题 I'm looking to find the max run of consecutive zeros in a DataFrame with the result grouped by user. I'm interested in running the RLE on usage. sample input: user--day--usage A-----1------0 A-----2------0 A-----3------1 B-----1------0 B-----2------1 B-----3------0 Desired output user---longest_run a - - - - 2 b - - - - 1 mydata <- mydata[order(mydata$user, mydata$day),] user <- unique(mydata$user) d2 <- data.frame(matrix(NA, ncol = 2, nrow = length(user))) names(d2) <- c("user", "longest_no