Features.count

Features.count(condition, points=None)

The number of features which satisfy the condition.

Parameters:
  • condition (function, query) –

    • function - accepts a feature as its only argument and returns a boolean value to indicate if the feature should be counted

    • query - string in the format ‘POINTNAME OPERATOR VALUE’ (i.e “pt1 < 10”, “id4 == yes”, or “row4 is nonZero”) where OPERATOR is separated from the POINTNAME and VALUE by whitespace characters. See nimble.match.QueryString for string requirements.

  • points (None, identifier, list of identifiers) – Only apply the condition function to a selection of points in each feature. May be a single point name or index, an iterable, container of point names and/or indices. None indicates application to all points.

Returns:

int

Examples

Count using a python function.

>>> def sumIsOne(ft):
...     return sum(ft) == 1
>>> X = nimble.identity(3)
>>> X.features.count(sumIsOne)
3

Count when the query string returns True.

>>> X = nimble.identity(3, pointNames=['pt1', 'pt2', 'pt3'])
>>> X.features.count("pt1 == 0")
2

Keywords: number, counts, tally