## Count specific condition in 2d-array

count number of elements in numpy array
numpy count occurrences in 2d array
numpy count condition
np.count zero
numpy find matching elements
python count number of occurrences in matrix
numpy count unique
subset numpy array by condition

Given a 2D Array, count the number data at column 3 where it is the same.

For example,

``` String[][] array = {
{ "red", "value1", "alpha"  },
{ "blue", "value2", "alpha"  },
{ "green", "value3", "alpha"  },
{ "black", "value4", "alpha" },
{ "grey", "value1", "beta"  },
{ "white", "value2", "beta"  },
};

int counter=0;
for(String[] subArray : array)
for(String string : subArray)
if(string.toLowerCase().equals("beta"))
counter++;

System.out.println(counter);
```

The output of the counter for beta = 2 and alpha = 4.

Assuming I don't know what is the exact name of the data in column 3, how I count the conditions? `if(string.toLowerCase().equals(???))`

Any help will be appreciated!

It could be something like this using `groupingBy` in java 8:

``` Arrays.stream(array)
.collect(Collectors.groupingBy(arr -> arr, Collectors.counting()));
```

Result will:

```{alpha=4, beta=2}
```

B.T.W If you want to ignore case, do it as:

```Arrays.stream(array)
.collect(Collectors.groupingBy(arr -> arr.toLowerCase(), Collectors.counting()));
```

NumPy: Count the number of elements satisfying the condition, If you want to replace an element that satisfies the conditions, see the following post. In the case of a two-dimensional array, axis=0 gives the count per processed for each row or column when parameter axis is specified. Count dates in a specific date range To count the dates that fall in a certain date range, you can also use either a COUNTIFS formula with two criteria or a combination of two COUNTIF functions. For example, the following formulas count the number of dates in cells C2 through C10 that fall between 1-Jun-2014 and 7-Jun-2014, inclusive:

Create a `Map<String, int>`

Look for the value of `string.toLowerCase` in the Map and if it is found increment the value of `int` else insert with the value of `1`

NumPy: Extract or delete elements, rows and columns that satisfy , Extract elements that satisfy the conditions Extract rows and columns that satisfy the post: NumPy: Count the number of elements satisfying the condition Even if the original ndarray is a multidimensional array, a flattened  python .count for multidimensional arrays (list of lists) Simple way to count number of specific elements in 2D array Python Assigning a variable the count of

There are many ways, but one way:

1. Create a new multidimensional array of types string:int.

2. Iteratethrough your array at the last index, and then check if it exists in your array you made.

3. If it exists, inremement the int to int+1.