transformer_from_callable_on_rows

gtda.mapper.transformer_from_callable_on_rows(func, validate=True)[source]

Construct a transformer from a callable acting on 1D arrays.

Given a callable which can act on 1D arrays, this function returns a fit-transformer which applies the callable to slices of 2D arrays along axis 1. When possible, the array output by the transformer’s fit_transform is two-dimensional.

Parameters
  • func (callable or None) – A callable object, or None which returns the identity transformer.

  • validate (bool, optional, default: True) – Whether the output transformer should implement input validation.

Returns

function_transformer – Output fit-transformer.

Return type

sklearn.preprocessing.FunctionTransformer object

Examples

>>> import numpy as np
>>> from gtda.mapper import transformer_from_callable_on_rows
>>> function_transformer = transformer_from_callable_on_rows(np.sum)
>>> X = np.array([[0, 1], [2, 3]])
>>> print(function_transformer.fit_transform(X))
[[1],
 [5]]