Points.calculate¶
- Points.calculate(function, points=None, *, useLog=None)¶
Apply a calculation to each point.
Return a new object that calculates the results of the given function on the specified points in this object, with output values collected into a new object that is returned upon completion.
- Parameters:
function (function) – Accepts a view of a point as an argument and returns the new values in that point.
points (point, list of points) – The subset of points to limit the calculation to. If None, the calculation will apply 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
See also
Examples
Apply calculation to all points; apply to all features.
>>> X = nimble.ones(3, 5) >>> addTwo = X.points.calculate(lambda pt: pt + 2) >>> addTwo <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 >
Apply calculation to all points; function modifies a specific feature. Note that the function recieves a read-only view of each point, so a copy is necessary to modify any specific data.
>>> def changeMiddleFeature(pt): ... ptList = pt.copy(to='python list', outputAs1D=True) ... ptList[2] += 4 ... return ptList >>> X = nimble.ones(3, 5) >>> changeMiddle = X.points.calculate(changeMiddleFeature) >>> changeMiddle <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 >
Apply calculation to a subset of points.
>>> ptNames = ['p1', 'p2', 'p3'] >>> X = nimble.identity(3, pointNames=ptNames) >>> calc = X.points.calculate(lambda pt: pt + 6, ... points=[2, 0]) >>> calc <Matrix 2pt x 3ft 0 1 2 ┌──────── p3 │ 6 6 7 p1 │ 7 6 6 >
Keywords: apply, modify, alter