Points.extract

Points.extract(toExtract=None, start=None, end=None, number=None, randomize=False, features=None, *, useLog=None)

Move certain points of this object into their own object.

A variety of methods for specifying the points to extract based on the provided parameters. If toExtract is not None, start and end must be None. If start or end is not None, toExtract must be None.

The nimble.match module contains many helpful functions that could be used for toExtract.

Parameters:
  • toExtract (identifier, list of identifiers, function, query) –

    • identifier - a name or index

    • list of identifiers - an iterable container of identifiers

    • function - accepts a point as its only argument and returns a boolean value to indicate if the point should be extracted. See nimble.match for common functions.

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

  • start (identifier) – Parameters indicating range based extraction. Begin the extraction at the location of start. Finish extracting at the inclusive end location. If only one of start and end are non-None, the other default to 0 and the number of values in each point, respectively.

  • end (identifier) – Parameters indicating range based extraction. Begin the extraction at the location of start. Finish extracting at the inclusive end location. If only one of start and end are non-None, the other default to 0 and the number of values in each point, respectively.

  • number (int) – The quantity of points that are to be extracted, the default None means unrestricted extraction. This can be provided on its own (toExtract, start and end are None) to the first number of points, or in conjuction with toExtract or start and end, to limit their output.

  • randomize (bool) – Indicates whether random sampling is to be used in conjunction with the number parameter. If randomize is False, the chosen points are determined by point order, otherwise it is uniform random across the space of possible points.

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

  • useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.

Returns:

nimble Base object

See also

retain, delete

Examples

Extract a single point.

>>> X = nimble.identity(3)
>>> X.points.setNames(['a', 'b', 'c'])
>>> single = X.points.extract('a')
>>> single
<Matrix 1pt x 3ft
     0  1  2
   ┌────────
 a │ 1  0  0
>
>>> X
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 b │ 0  1  0
 c │ 0  0  1
>

Extract multiple points.

>>> X = nimble.identity(3)
>>> X.points.setNames(['a', 'b', 'c'])
>>> multiple = X.points.extract(['a', 2])
>>> multiple
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 a │ 1  0  0
 c │ 0  0  1
>
>>> X
<Matrix 1pt x 3ft
     0  1  2
   ┌────────
 b │ 0  1  0
>

Extract point when the function returns True.

>>> X = nimble.data([[1, 2, 3], [4, 5, 6], [-1, -2, -3]])
>>> X.points.setNames(['a', 'b', 'c'])
>>> positives = X.points.extract(nimble.match.allPositive)
>>> positives
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 a │ 1  2  3
 b │ 4  5  6
>
>>> X
<Matrix 1pt x 3ft
     0   1   2
   ┌───────────
 c │ -1  -2  -3
>

Extract point when the query string returns True.

>>> X = nimble.identity(3, pointNames=['a', 'b', 'c'],
...                     featureNames=['f1', 'f2', 'f3'])
>>> strFunc = X.points.extract("f2 != 0")
>>> strFunc
<Matrix 1pt x 3ft
     f1  f2  f3
   ┌───────────
 b │ 0   1   0
>
>>> X
<Matrix 2pt x 3ft
     f1  f2  f3
   ┌───────────
 a │ 1   0   0
 c │ 0   0   1
>

Extract points from the inclusive start to the inclusive end.

>>> X = nimble.identity(3)
>>> X.points.setNames(['a', 'b', 'c'])
>>> startEnd = X.points.extract(start=1, end=2)
>>> startEnd
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 b │ 0  1  0
 c │ 0  0  1
>
>>> X
<Matrix 1pt x 3ft
     0  1  2
   ┌────────
 a │ 1  0  0
>

Select a set number to extract, starting from the first point.

>>> X = nimble.identity(3)
>>> X.points.setNames(['a', 'b', 'c'])
>>> numberNoRandom = X.points.extract(number=2)
>>> numberNoRandom
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 a │ 1  0  0
 b │ 0  1  0
>
>>> X
<Matrix 1pt x 3ft
     0  1  2
   ┌────────
 c │ 0  0  1
>

Select a set number to extract, choosing points at random.

>>> nimble.random.setSeed(42)
>>> X = nimble.identity(3)
>>> X.points.setNames(['a', 'b', 'c'])
>>> numberRandom = X.points.extract(number=2, randomize=True)
>>> numberRandom
<Matrix 2pt x 3ft
     0  1  2
   ┌────────
 c │ 0  0  1
 a │ 1  0  0
>
>>> X
<Matrix 1pt x 3ft
     0  1  2
   ┌────────
 b │ 0  1  0
>

Keywords: move, pull, separate, withdraw, cut, hsplit, filter