Points.transform

Points.transform(function, points=None, *, useLog=None)

Modify this object by applying a function to each point.

Perform an inplace modification of the data in this object through the application of the provided function to the points or subset of points in this object.

Parameters:
  • function – Must accept the view of a point as an argument.

  • points (identifier, list of identifiers) – 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.

Examples

Transform all points; apply to all features.

>>> X = nimble.ones(3, 5)
>>> X.points.transform(lambda pt: pt + 2)
>>> X
<Matrix 3pt x 5ft
     0  1  2  3  4
   ┌──────────────
 0 │ 3  3  3  3  3
 1 │ 3  3  3  3  3
 2 │ 3  3  3  3  3
>

Transform all points; apply to certain features. Note that the function recieves a read-only view of each point, so we need to make a copy in order to modify any specific data.

>>> def transformMiddleFeature(pt):
...     ptList = pt.copy(to='python list', outputAs1D=True)
...     ptList[2] += 4
...     return ptList
>>> X = nimble.ones(3, 5)
>>> X.points.transform(transformMiddleFeature)
>>> X
<Matrix 3pt x 5ft
     0  1  2  3  4
   ┌──────────────
 0 │ 1  1  5  1  1
 1 │ 1  1  5  1  1
 2 │ 1  1  5  1  1
>

Transform a subset of points.

>>> X = nimble.ones(3, 5)
>>> X.points.transform(lambda pt: pt + 6, points=[0, 2])
>>> X
<Matrix 3pt x 5ft
     0  1  2  3  4
   ┌──────────────
 0 │ 7  7  7  7  7
 1 │ 1  1  1  1  1
 2 │ 7  7  7  7  7
>