neuraxle.steps.numpy

Module-level documentation for neuraxle.steps.numpy. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:

Inheritance diagram of neuraxle.steps.numpy

Pipeline Steps Based on NumPy

Those steps works with NumPy (np) arrays.

Classes

AddN([add])

Step to add a scalar to a numpy array.

MultiplyByN([multiply_by])

Step to multiply a numpy array.

NumpyAbs()

Compute np.abs.

NumpyArgMax([axis])

Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.argmax.html>̀_ at the given axis.

NumpyConcatenateInnerFeatures()

Numpy concatenation step where the concatenation is performed along axis=-1.

NumpyConcatenateOnAxis(axis)

Numpy concetenation step where the concatenation is performed along the specified custom axis.

NumpyConcatenateOnAxisIfNotEmpty(axis)

Numpy concatenation step where the concatenation is performed along the specified custom axis.

NumpyConcatenateOuterBatch()

Numpy concetenation step where the concatenation is performed along axis=0.

NumpyFFT([axis])

Compute time series FFT using np.fft.rfft

NumpyFlattenDatum()

NumpyMax([axis])

Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.max.html>̀_ at the given axis.

NumpyMean([axis])

Compute np.mean at the given axis.

NumpyMedian([axis])

Compute np.median at the given axis.

NumpyMin([axis])

Compute np.min at the given axis.

NumpyRavel()

Return a contiguous flattened array using `np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>̀_

NumpyReshape(new_shape)

Reshape numpy array in data inputs.

NumpyShapePrinter(custom_message)

NumpyTranspose(axes)

OneHotEncoder(nb_columns, name)

Step to one hot a set of columns.

Sum(axis)

Step sum numpy array using np.sum.

ToNumpy()

Convert data inputs, and expected outputs to a numpy array.

Examples using neuraxle.steps.numpy.MultiplyByN

Examples using neuraxle.steps.numpy.NumpyRavel

Examples using neuraxle.steps.numpy.NumpyShapePrinter

Examples using neuraxle.steps.numpy.NumpyTranspose


class neuraxle.steps.numpy.NumpyFlattenDatum[source]

Bases: neuraxle.base.BaseTransformer

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyConcatenateOnAxis(axis)[source]

Bases: neuraxle.base.BaseTransformer

Numpy concetenation step where the concatenation is performed along the specified custom axis.

__init__(axis)[source]

Create a numpy concatenate on custom axis object. :param axis: the axis where the concatenation is performed. :return: NumpyConcatenateOnAxis instance.

_transform_data_container(data_container, context)[source]

Handle transform.

Parameters
  • data_container – the data container to join

  • context – execution context

Returns

transformed data container

transform(data_inputs)[source]

Apply the concatenation transformation along the specified axis. :param data_inputs: :return: Numpy array

_concat(data_inputs)[source]
_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyConcatenateOnAxisIfNotEmpty(axis)[source]

Bases: neuraxle.base.BaseTransformer

Numpy concatenation step where the concatenation is performed along the specified custom axis.

__init__(axis)[source]

Create a numpy concatenate on custom axis object. :param axis: the axis where the concatenation is performed. :return: NumpyConcatenateOnAxis instance.

_transform_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext)[source]

Handle transform.

Parameters
Returns

transformed data container

transform(data_inputs)[source]

Apply the concatenation transformation along the specified axis. :param data_inputs: :return: Numpy array

_concat(data_inputs)[source]
_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyConcatenateInnerFeatures[source]

Bases: neuraxle.steps.numpy.NumpyConcatenateOnAxis

Numpy concatenation step where the concatenation is performed along axis=-1.

__init__()[source]

Create a numpy concatenate inner features object. :return: NumpyConcatenateOnAxis instance.

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyConcatenateOuterBatch[source]

Bases: neuraxle.steps.numpy.NumpyConcatenateOnAxis

Numpy concetenation step where the concatenation is performed along axis=0.

__init__()[source]

Create a numpy concatenate outer batch object. :return: NumpyConcatenateOnAxis instance which is inherited by base step.

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyTranspose(axes: Sequence[int] = None)[source]

Bases: neuraxle.base.BaseTransformer

__init__(axes: Sequence[int] = None)[source]

Initialize self. See help(type(self)) for accurate signature.

_transform_data_container(data_container, context)[source]

Handle transform.

Parameters
  • data_container – the data container to join

  • context – execution context

Returns

transformed data container

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

_transpose(data_inputs)[source]
_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyShapePrinter(custom_message: str = '')[source]

Bases: neuraxle.base.BaseTransformer

__init__(custom_message: str = '')[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

_print(data_inputs)[source]
_print_one(data_input)[source]
_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.MultiplyByN(multiply_by=1)[source]

Bases: neuraxle.base.BaseTransformer

Step to multiply a numpy array. Accepts an integer for the number to multiply by.

Example usage:

pipeline = Pipeline([
    MultiplyByN(3)
])
outputs = pipeline.transform(np.array([1])
# outputs => np.array([3])

See also

BaseStep

__init__(multiply_by=1)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.AddN(add=1)[source]

Bases: neuraxle.base.BaseTransformer

Step to add a scalar to a numpy array. Accepts an integer for the number to add to every data inputs.

Example usage:

pipeline = Pipeline([
    AddN(1)
])
outputs = pipeline.transform(np.array([1])
# outputs => np.array([2])

See also

BaseStep

__init__(add=1)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.Sum(axis)[source]

Bases: neuraxle.base.BaseTransformer

Step sum numpy array using np.sum.

Example usage:

pipeline = Pipeline([
    Sum(axis=-1)
])

outputs = pipeline.transform(np.array([1, 2, 3])
# outputs => 6)

See also

BaseStep

__init__(axis)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.OneHotEncoder(nb_columns, name)[source]

Bases: neuraxle.base.BaseTransformer

Step to one hot a set of columns. Accepts Integer Columns and converts it ot a one_hot. Rounds floats to integer for safety in the transform.

Example usage:

  1. Set up data

import numpy as np
a = np.array([1,0,3])
b = np.array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])
  1. Do the actual conversion

from neuraxle.steps.numpy import OneHotEncoder
encoder = OneHotEncoder(nb_columns=4)
b_pred = encoder.transform(a)
  1. Assert it works

assert b_pred == b
__init__(nb_columns, name)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform data inputs using one hot encoding, adding no_columns to the -1 axis. :param data_inputs: data inputs to encode :return: one hot encoded data inputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.ToNumpy[source]

Bases: neuraxle.base.ForceHandleMixin, neuraxle.base.BaseTransformer

Convert data inputs, and expected outputs to a numpy array.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

_will_process(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) -> (<class 'neuraxle.data_container.DataContainer'>, <class 'neuraxle.base.ExecutionContext'>)[source]

Apply side effects before any step method. :type context: ExecutionContext :type data_container: DataContainer :param data_container: data container :param context: execution context :return: (data container, execution context)

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyReshape(new_shape)[source]

Bases: neuraxle.base.BaseTransformer

Reshape numpy array in data inputs.

import numpy as np
a = np.array([1,0,3])
outputs = NumpyReshape(shape=(-1,1)).transform(a)
assert np.array_equal(outputs, np.array([[1],[0],[3]]))

See also

BaseStep

__init__(new_shape)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyRavel[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Return a contiguous flattened array using `np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>̀_

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Flatten numpy array using ̀np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>`_

Parameters

data_inputs

Returns

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyFFT(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute time series FFT using np.fft.rfft

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize time series data with FFT using `np.fft.rfft <>̀_

Parameters

data_inputs – time series data of 3D shape: [batch_size, time_steps, sensors_readings]

Returns

featurized data is of 2D shape: [batch_size, n_features]

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyAbs[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute np.abs.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a absolute value transformation.

Parameters

data_inputs – data inputs

Returns

absolute data inputs

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyMean(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute np.mean at the given axis.

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a mean.

Parameters

data_inputs – data inputs

Returns

data inputs mean for the given axis

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyMedian(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute np.median at the given axis.

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a median.

Parameters

data_inputs – data inputs

Returns

data inputs median for the given axis

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyMin(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute np.min at the given axis.

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a min.

Parameters

data_inputs – data inputs

Returns

min value for the given axis

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyMax(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.max.html>̀_ at the given axis.

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a max.

Parameters

data_inputs – 3D time series of shape [batch_size, time_steps, sensors]

Returns

max value for the given axis

_abc_impl = <_abc_data object>
class neuraxle.steps.numpy.NumpyArgMax(axis=None)[source]

Bases: neuraxle.base.NonFittableMixin, neuraxle.base.BaseStep

Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.argmax.html>̀_ at the given axis.

__init__(axis=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Will featurize data with a max.

Parameters

data_inputs – 3D time series of shape [batch_size, time_steps, sensors]

Returns

max value for the given axis

_abc_impl = <_abc_data object>