Features.copy

Features.copy(toCopy=None, start=None, end=None, number=None, randomize=False, points=None, *, useLog=None)

Copy certain features of this object.

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

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

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

    • identifier - a name or index

    • list of identifiers - an iterable container of identifiers

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

    • 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.

  • start (identifier) – Parameters indicating range based copying. Begin the copying at the location of start. Finish copying 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 feature, respectively.

  • end (identifier) – Parameters indicating range based copying. Begin the copying at the location of start. Finish copying 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 feature, respectively.

  • number (int) – The quantity of features that are to be copied, the default None means unrestricted copying. This can be provided on its own (toCopy, start and end are None) to the first number of features, or in conjuction with toCopy 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 features are determined by feature order, otherwise it is uniform random across the space of possible features.

  • points (None, identifier, list of identifiers) – Only apply the target 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.

  • 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

Examples

>>> lst = [[0, 1, 2, 3],
...        [0, 1, 2, 3],
...        [0, 1, 2, 3],
...        [0, 1, 2, 3]]
>>> X = nimble.data(lst,
...                 pointNames=['a', 'b', 'c', 'd'],
...                 featureNames=['0', '1', '2', '3'])
>>> single = X.features.copy('0')
>>> single
<Matrix 4pt x 1ft
     0
   ┌──
 a │ 0
 b │ 0
 c │ 0
 d │ 0
>
>>> multiple = X.features.copy(['0', 3])
>>> multiple
<Matrix 4pt x 2ft
     0  3
   ┌─────
 a │ 0  3
 b │ 0  3
 c │ 0  3
 d │ 0  3
>
>>> func = X.features.copy(nimble.match.allZero)
>>> func
<Matrix 4pt x 1ft
     0
   ┌──
 a │ 0
 b │ 0
 c │ 0
 d │ 0
>
>>> strFunc = X.features.copy("a >= 2")
>>> strFunc
<Matrix 4pt x 2ft
     2  3
   ┌─────
 a │ 2  3
 b │ 2  3
 c │ 2  3
 d │ 2  3
>
>>> startEnd = X.features.copy(start=1, end=3) # Note: Inclusive
>>> startEnd
<Matrix 4pt x 3ft
     1  2  3
   ┌────────
 a │ 1  2  3
 b │ 1  2  3
 c │ 1  2  3
 d │ 1  2  3
>
>>> numberNoRandom = X.features.copy(number=2)
>>> numberNoRandom
<Matrix 4pt x 2ft
     0  1
   ┌─────
 a │ 0  1
 b │ 0  1
 c │ 0  1
 d │ 0  1
>
>>> nimble.random.setSeed(42)
>>> numberRandom = X.features.copy(number=2, randomize=True)
>>> numberRandom
<Matrix 4pt x 2ft
     0  3
   ┌─────
 a │ 0  3
 b │ 0  3
 c │ 0  3
 d │ 0  3
>

Keywords: duplicate, replicate, clone, filter