FDataGrid#

class skfda.representation.grid.FDataGrid(data_matrix, grid_points=None, *, sample_points=None, domain_range=None, dataset_name=None, argument_names=None, coordinate_names=None, sample_names=None, extrapolation=None, interpolation=None)[source]#

Represent discretised functional data.

Class for representing functional data as a set of curves discretised in a grid of points.

Attributes:
  • data_matrix – a matrix where each entry of the first axis contains the values of a functional datum evaluated at the points of discretisation.

  • grid_points – 2 dimension matrix where each row contains the points of dicretisation for each axis of data_matrix.

  • domain_range – 2 dimension matrix where each row contains the bounds of the interval in which the functional data is considered to exist for each one of the axies.

  • dataset_name – name of the dataset.

  • argument_names – tuple containing the names of the different arguments.

  • coordinate_names – tuple containing the names of the different coordinate functions.

  • extrapolation – defines the default type of extrapolation. By default None, which does not apply any type of extrapolation. See Extrapolation for detailled information of the types of extrapolation.

  • interpolation – Defines the type of interpolation applied in evaluate.

Parameters:
  • data_matrix (ArrayLike) –

  • grid_points (Optional[GridPointsLike]) –

  • sample_points (Optional[GridPointsLike]) –

  • domain_range (Optional[DomainRangeLike]) –

  • dataset_name (str | None) –

  • argument_names (Optional[LabelTupleLike]) –

  • coordinate_names (Optional[LabelTupleLike]) –

  • sample_names (Optional[LabelTupleLike]) –

  • extrapolation (Optional[ExtrapolationLike]) –

  • interpolation (Optional[Evaluator]) –

Examples

Representation of a functional data object with 2 samples representing a function \(f : \mathbb{R}\longmapsto\mathbb{R}\), with 3 discretization points.

>>> data_matrix = [[1, 2, 3], [4, 5, 6]]
>>> grid_points = [2, 4, 5]
>>> FDataGrid(data_matrix, grid_points)
FDataGrid(
    array([[[ 1.],
            [ 2.],
            [ 3.]],

           [[ 4.],
            [ 5.],
            [ 6.]]]),
    grid_points=(array([ 2., 4., 5.]),),
    domain_range=((2.0, 5.0),),
    ...)

The number of columns of data_matrix have to be the length of grid_points.

>>> FDataGrid(np.array([1,2,4,5,8]), range(6))
Traceback (most recent call last):
    ....
ValueError: Incorrect dimension in data_matrix and grid_points...

FDataGrid support higher dimensional data both in the domain and image. Representation of a functional data object with 2 samples representing a function \(f : \mathbb{R}\longmapsto\mathbb{R}^2\).

>>> data_matrix = [[[1, 0.3], [2, 0.4]], [[2, 0.5], [3, 0.6]]]
>>> grid_points = [2, 4]
>>> fd = FDataGrid(data_matrix, grid_points)
>>> fd.dim_domain, fd.dim_codomain
(1, 2)

Representation of a functional data object with 2 samples representing a function \(f : \mathbb{R}^2\longmapsto\mathbb{R}\).

>>> data_matrix = [[[1, 0.3], [2, 0.4]], [[2, 0.5], [3, 0.6]]]
>>> grid_points = [[2, 4], [3,6]]
>>> fd = FDataGrid(data_matrix, grid_points)
>>> fd.dim_domain, fd.dim_codomain
(2, 1)

Methods

__init__(data_matrix[, grid_points, ...])

Construct a FDataGrid object.

argmax([skipna])

Return the index of maximum value.

argmin([skipna])

Return the index of minimum value.

argsort(*args[, ascending, kind, na_position])

Return the indices that would sort this array.

astype(dtype[, copy])

Cast to a new dtype.

compose(fd, *[, eval_points])

Composition of functions.

concatenate(*others[, as_coordinates])

Join samples from a similar FDataGrid object.

copy(*[, deep, data_matrix, grid_points, ...])

Return a copy of the FDataGrid.

cov()

Compute the covariance.

delete(loc)

derivative(*[, order, method])

Differentiate a FDataGrid object.

dropna()

Return ExtensionArray without NA values.

equals(other)

Comparison of FDataGrid objects.

evaluate(eval_points, *[, derivative, ...])

Evaluate the object at a list of values or a grid.

factorize([na_sentinel, use_na_sentinel])

Encode the extension array as an enumerated type.

fillna([value, method, limit])

Fill NA/NaN values using the specified method.

gmean()

Compute the geometric mean of all samples in the FDataGrid object.

insert(loc, item)

Insert an item at the given position.

integrate(*[, domain])

Integration of the FData object.

isin(values)

Pointwise comparison for set containment in the given values.

isna()

Return a 1-D array indicating if each value is missing.

mean(*[, axis, dtype, out, keepdims, skipna])

Compute the mean of all the samples.

plot(*args, **kwargs)

Plot the FDatGrid object.

ravel([order])

Return a flattened view on this array.

repeat(repeats[, axis])

Repeat elements of a ExtensionArray.

restrict(domain_range)

Restrict the functions to a new domain range.

round([decimals, out])

Evenly round to the given number of decimals.

scatter(*args, **kwargs)

Scatter plot of the FDatGrid object.

searchsorted(value[, side, sorter])

Find indices where elements should be inserted to maintain order.

shift(shifts, *[, restrict_domain, ...])

Perform a shift of the curves.

sum(*[, axis, out, keepdims, skipna, min_count])

Compute the sum of all the samples.

take(indices[, allow_fill, fill_value, axis])

Take elements from an array.

to_basis(basis, **kwargs)

Return the basis representation of the object.

to_grid([grid_points, sample_points])

Return the discrete representation of the object.

to_numpy([dtype, copy, na_value])

Convert to a NumPy ndarray.

tolist()

Return a list of the values.

transpose(*axes)

Return a transposed view on this array.

unique()

Compute the ExtensionArray of unique values.

var()

Compute the variance of a set of samples in a FDataGrid object.

view([dtype])

Return a view on the array.

__init__(data_matrix, grid_points=None, *, sample_points=None, domain_range=None, dataset_name=None, argument_names=None, coordinate_names=None, sample_names=None, extrapolation=None, interpolation=None)[source]#

Construct a FDataGrid object.

Parameters:
  • data_matrix (ArrayLike) –

  • grid_points (Union[ArrayLike, Sequence[ArrayLike]] | None) –

  • sample_points (Union[ArrayLike, Sequence[ArrayLike]] | None) –

  • domain_range (Tuple[Tuple[float, float], ...] | Sequence[float] | Sequence[Sequence[float]] | None) –

  • dataset_name (str | None) –

  • argument_names (Sequence[str | None] | None) –

  • coordinate_names (Sequence[str | None] | None) –

  • sample_names (Sequence[str | None] | None) –

  • extrapolation (Evaluator | Literal['bounds', 'exception', 'nan', 'none', 'periodic', 'zeros'] | None) –

  • interpolation (Evaluator | None) –

argmax(skipna=True)#

Return the index of maximum value.

In case of multiple occurrences of the maximum value, the index corresponding to the first occurrence is returned.

Parameters:

skipna (bool, default True) –

Return type:

int

See also

ExtensionArray.argmin

argmin(skipna=True)#

Return the index of minimum value.

In case of multiple occurrences of the minimum value, the index corresponding to the first occurrence is returned.

Parameters:

skipna (bool, default True) –

Return type:

int

See also

ExtensionArray.argmax

argsort(*args, ascending=True, kind='quicksort', na_position='last', **kwargs)#

Return the indices that would sort this array.

Parameters:
  • ascending (bool, default True) – Whether the indices should result in an ascending or descending sort.

  • kind ({'quicksort', 'mergesort', 'heapsort', 'stable'}, optional) – Sorting algorithm.

  • *args – Passed through to numpy.argsort().

  • **kwargs – Passed through to numpy.argsort().

  • na_position (str) –

Returns:

Array of indices that sort self. If NaN values are contained, NaN values are placed at the end.

Return type:

np.ndarray[np.intp]

See also

numpy.argsort

Sorting implementation used internally.

astype(dtype, copy=True)#

Cast to a new dtype.

Parameters:
Return type:

Any

compose(fd, *, eval_points=None)[source]#

Composition of functions.

Performs the composition of functions.

Parameters:
  • fd (T) – FData object to make the composition. Should have the same number of samples and image dimension equal to 1.

  • eval_points (Union[ArrayLike, Sequence[ArrayLike]] | None) – Points to perform the evaluation.

  • self (T) –

Returns:

Function representing the composition.

Return type:

T

concatenate(*others, as_coordinates=False)[source]#

Join samples from a similar FDataGrid object.

Joins samples from another FDataGrid object if it has the same dimensions and sampling points.

Parameters:
  • others (T) – Objects to be concatenated.

  • as_coordinates (bool) – If False concatenates as new samples, else, concatenates the other functions as new components of the image. Defaults to false.

  • self (T) –

Returns:

FDataGrid object with the samples from the original objects.

Return type:

T

Examples

>>> fd = FDataGrid([1,2,4,5,8], range(5))
>>> fd_2 = FDataGrid([3,4,7,9,2], range(5))
>>> fd.concatenate(fd_2)
FDataGrid(
    array([[[ 1.],
            [ 2.],
            [ 4.],
            [ 5.],
            [ 8.]],

           [[ 3.],
            [ 4.],
            [ 7.],
            [ 9.],
            [ 2.]]]),
    grid_points=(array([ 0., 1., 2., 3., 4.]),),
    domain_range=((0.0, 4.0),),
    ...)
copy(*, deep=False, data_matrix=None, grid_points=None, sample_points=None, domain_range=None, dataset_name=None, argument_names=None, coordinate_names=None, sample_names=None, extrapolation=None, interpolation=None)[source]#

Return a copy of the FDataGrid.

If an argument is provided the corresponding attribute in the new copy is updated.

Parameters:
  • self (T) –

  • deep (bool) –

  • data_matrix (ArrayLike | None) –

  • grid_points (Union[ArrayLike, Sequence[ArrayLike]] | None) –

  • sample_points (Union[ArrayLike, Sequence[ArrayLike]] | None) –

  • domain_range (Tuple[Tuple[float, float], ...] | Sequence[float] | Sequence[Sequence[float]] | None) –

  • dataset_name (str | None) –

  • argument_names (Sequence[str | None] | None) –

  • coordinate_names (Sequence[str | None] | None) –

  • sample_names (Sequence[str | None] | None) –

  • extrapolation (Evaluator | Literal['bounds', 'exception', 'nan', 'none', 'periodic', 'zeros'] | None) –

  • interpolation (Evaluator | None) –

Return type:

T

cov()[source]#

Compute the covariance.

Calculates the covariance matrix representing the covariance of the functional samples at the observation points.

Returns:

Covariance function.

Parameters:

self (T) –

Return type:

T

delete(loc)#
Parameters:
Return type:

ExtensionArrayT

derivative(*, order=1, method=None)[source]#

Differentiate a FDataGrid object.

By default, it is calculated using central finite differences when possible. In the extremes, forward and backward finite differences with accuracy 2 are used.

Parameters:
  • order (int) – Order of the derivative. Defaults to one.

  • method (Optional[Basis]) – Method to use to compute the derivative. If None (the default), finite differences are used. In a basis object is passed the grid is converted to a basis representation and the derivative is evaluated using that representation.

  • self (T) –

Returns:

Derivative function.

Return type:

T

Examples

First order derivative

>>> fdata = FDataGrid([1,2,4,5,8], range(5))
>>> fdata.derivative()
FDataGrid(
    array([[[ 0.5],
            [ 1.5],
            [ 1.5],
            [ 2. ],
            [ 4. ]]]),
    grid_points=(array([ 0., 1., 2., 3., 4.]),),
    domain_range=((0.0, 4.0),),
    ...)

Second order derivative

>>> fdata = FDataGrid([1,2,4,5,8], range(5))
>>> fdata.derivative(order=2)
FDataGrid(
    array([[[ 3.],
            [ 1.],
            [-1.],
            [ 2.],
            [ 5.]]]),
    grid_points=(array([ 0., 1., 2., 3., 4.]),),
    domain_range=((0.0, 4.0),),
    ...)
dropna()#

Return ExtensionArray without NA values.

Returns:

valid

Return type:

ExtensionArray

Parameters:

self (ExtensionArrayT) –

equals(other)[source]#

Comparison of FDataGrid objects.

Parameters:

other (object) –

Return type:

bool

evaluate(eval_points, *, derivative=0, extrapolation=None, grid=False, aligned=True)#

Evaluate the object at a list of values or a grid.

Deprecated since version 0.8: Use normal calling notation instead.

Parameters:
  • eval_points (_SupportsArray[dtype] | _NestedSequence[_SupportsArray[dtype]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype] | _NestedSequence[_SupportsArray[dtype]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | Iterable[_SupportsArray[dtype] | _NestedSequence[_SupportsArray[dtype]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | Sequence[_SupportsArray[dtype] | _NestedSequence[_SupportsArray[dtype]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]]]) – List of points where the functions are evaluated. If grid is True, a list of axes, one per domain dimension, must be passed instead. If aligned is True, then a list of lists (of points or axes, as explained) must be passed, with one list per sample.

  • derivative (int) – Deprecated. Order of the derivative to evaluate.

  • extrapolation (Evaluator | Literal['bounds', 'exception', 'nan', 'none', 'periodic', 'zeros'] | None) – Controls the extrapolation mode for elements outside the domain range. By default it is used the mode defined during the instance of the object.

  • grid (bool) – Whether to evaluate the results on a grid spanned by the input arrays, or at points specified by the input arrays. If true the eval_points should be a list of size dim_domain with the corresponding times for each axis. The return matrix has shape n_samples x len(t1) x len(t2) x … x len(t_dim_domain) x dim_codomain. If the domain dimension is 1 the parameter has no efect. Defaults to False.

  • aligned (bool) – Whether the input points are the same for each sample, or an array of points per sample is passed.

Returns:

Matrix whose rows are the values of the each function at the values specified in eval_points.

Return type:

ndarray[Any, dtype[float64]]

factorize(na_sentinel=_NoDefault.no_default, use_na_sentinel=_NoDefault.no_default)#

Encode the extension array as an enumerated type.

Parameters:
  • na_sentinel (int, default -1) –

    Value to use in the codes array to indicate missing values.

    Deprecated since version 1.5.0: The na_sentinel argument is deprecated and will be removed in a future version of pandas. Specify use_na_sentinel as either True or False.

  • use_na_sentinel (bool, default True) –

    If True, the sentinel -1 will be used for NaN values. If False, NaN values will be encoded as non-negative integers and will not drop the NaN from the uniques of the values.

    New in version 1.5.0.

Returns:

  • codes (ndarray) – An integer NumPy array that’s an indexer into the original ExtensionArray.

  • uniques (ExtensionArray) – An ExtensionArray containing the unique values of self.

    Note

    uniques will not contain an entry for the NA value of the ExtensionArray if there are any missing values present in self.

Return type:

tuple[np.ndarray, ExtensionArray]

See also

factorize

Top-level factorize method that dispatches here.

Notes

pandas.factorize() offers a sort keyword as well.

fillna(value=None, method=None, limit=None)#

Fill NA/NaN values using the specified method.

Parameters:
  • value (scalar, array-like) – If a scalar value is passed it is used to fill all missing values. Alternatively, an array-like ‘value’ can be given. It’s expected that the array-like have the same length as ‘self’.

  • method ({'backfill', 'bfill', 'pad', 'ffill', None}, default None) – Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap.

  • limit (int, default None) – If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled.

  • self (ExtensionArrayT) –

Returns:

With NA/NaN filled.

Return type:

ExtensionArray

gmean()[source]#

Compute the geometric mean of all samples in the FDataGrid object.

Returns:

A FDataGrid object with just one sample representing the geometric mean of all the samples in the original FDataGrid object.

Parameters:

self (T) –

Return type:

T

insert(loc, item)#

Insert an item at the given position.

Parameters:
  • loc (int) –

  • item (scalar-like) –

  • self (ExtensionArrayT) –

Return type:

same type as self

Notes

This method should be both type and dtype-preserving. If the item cannot be held in an array of this type/dtype, either ValueError or TypeError should be raised.

The default implementation relies on _from_sequence to raise on invalid items.

integrate(*, domain=None)[source]#

Integration of the FData object.

The integration is performed over the whole domain. Thus, for a function of several variables this will be a multiple integral.

For a vector valued function the vector of integrals will be returned.

Parameters:
  • domain (Tuple[Tuple[float, float], ...] | None) – Domain range where we want to integrate. By default is None as we integrate on the whole domain.

  • self (T) –

Returns:

NumPy array of size (n_samples, dim_codomain) with the integrated data.

Return type:

ndarray[Any, dtype[float64]]

Examples

>>> fdata = FDataGrid([1,2,4,5,8], range(5))
>>> fdata.integrate()
array([[ 15.]])
isin(values)#

Pointwise comparison for set containment in the given values.

Roughly equivalent to np.array([x in values for x in self])

Parameters:

values (Sequence) –

Return type:

np.ndarray[bool]

isna()[source]#

Return a 1-D array indicating if each value is missing.

Returns:

Positions of NA.

Return type:

na_values

mean(*, axis=None, dtype=None, out=None, keepdims=False, skipna=False)#

Compute the mean of all the samples.

Parameters:
  • axis (None) – Used for compatibility with numpy. Must be None or 0.

  • dtype (None) – Used for compatibility with numpy. Must be None.

  • out (None) – Used for compatibility with numpy. Must be None.

  • keepdims (bool) – Used for compatibility with numpy. Must be False.

  • skipna (bool) – Wether the NaNs are ignored or not.

  • self (T) –

Returns:

A FData object with just one sample representing the mean of all the samples in the original object.

Return type:

T

plot(*args, **kwargs)#

Plot the FDatGrid object.

Parameters:
  • args (Any) – Positional arguments to be passed to the class GraphPlot.

  • kwargs (Any) – Keyword arguments to be passed to the class GraphPlot.

Returns:

Figure object in which the graphs are plotted.

Return type:

Figure

ravel(order='C')#

Return a flattened view on this array.

Parameters:

order ({None, 'C', 'F', 'A', 'K'}, default 'C') –

Return type:

ExtensionArray

Notes

  • Because ExtensionArrays are 1D-only, this is a no-op.

  • The “order” argument is ignored, is for compatibility with NumPy.

repeat(repeats, axis=None)#

Repeat elements of a ExtensionArray.

Returns a new ExtensionArray where each element of the current ExtensionArray is repeated consecutively a given number of times.

Parameters:
  • repeats (int or array of ints) – The number of repetitions for each element. This should be a non-negative integer. Repeating 0 times will return an empty ExtensionArray.

  • axis (None) – Must be None. Has no effect but is accepted for compatibility with numpy.

  • self (ExtensionArrayT) –

Returns:

repeated_array – Newly created ExtensionArray with repeated elements.

Return type:

ExtensionArray

See also

Series.repeat

Equivalent function for Series.

Index.repeat

Equivalent function for Index.

numpy.repeat

Similar method for numpy.ndarray.

ExtensionArray.take

Take arbitrary positions.

Examples

>>> cat = pd.Categorical(['a', 'b', 'c'])
>>> cat
['a', 'b', 'c']
Categories (3, object): ['a', 'b', 'c']
>>> cat.repeat(2)
['a', 'a', 'b', 'b', 'c', 'c']
Categories (3, object): ['a', 'b', 'c']
>>> cat.repeat([1, 2, 3])
['a', 'b', 'b', 'c', 'c', 'c']
Categories (3, object): ['a', 'b', 'c']
restrict(domain_range)[source]#

Restrict the functions to a new domain range.

Parameters:
Returns:

Restricted function.

Return type:

T

round(decimals=0, out=None)[source]#

Evenly round to the given number of decimals.

Deprecated since version 0.6: Use numpy.round() function instead.

Parameters:
  • decimals (int) – Number of decimal places to round to. If decimals is negative, it specifies the number of positions to the left of the decimal point. Defaults to 0.

  • out (FDataGrid | None) – FDataGrid where to place the result, if any.

Returns:

Returns a FDataGrid object where all elements in its data_matrix are rounded.

Return type:

FDataGrid

scatter(*args, **kwargs)[source]#

Scatter plot of the FDatGrid object.

Parameters:
  • args (Any) – Positional arguments to be passed to the class ScatterPlot.

  • kwargs (Any) – Keyword arguments to be passed to the class ScatterPlot.

Returns:

Figure object in which the graphs are plotted.

Return type:

Figure

searchsorted(value, side='left', sorter=None)#

Find indices where elements should be inserted to maintain order.

Find the indices into a sorted array self (a) such that, if the corresponding elements in value were inserted before the indices, the order of self would be preserved.

Assuming that self is sorted:

side

returned index i satisfies

left

self[i-1] < value <= self[i]

right

self[i-1] <= value < self[i]

Parameters:
  • value (array-like, list or scalar) – Value(s) to insert into self.

  • side ({'left', 'right'}, optional) – If ‘left’, the index of the first suitable location found is given. If ‘right’, return the last such index. If there is no suitable index, return either 0 or N (where N is the length of self).

  • sorter (1-D array-like, optional) – Optional array of integer indices that sort array a into ascending order. They are typically the result of argsort.

Returns:

If value is array-like, array of insertion points. If value is scalar, a single integer.

Return type:

array of ints or int

See also

numpy.searchsorted

Similar method from NumPy.

shift(shifts, *, restrict_domain=False, extrapolation=None, grid_points=None)[source]#

Perform a shift of the curves.

The i-th shifted function \(y_i\) has the form

\[y_i(t) = x_i(t + \delta_i)\]

where \(x_i\) is the i-th original function and \(delta_i\) is the shift performed for that function, that must be a vector in the domain space.

Note that a positive shift moves the graph of the function in the negative direction and vice versa.

Parameters:
  • shifts (ArrayLike | float) – List with the shifts corresponding for each sample or numeric with the shift to apply to all samples.

  • restrict_domain (bool) – If True restricts the domain to avoid the evaluation of points outside the domain using extrapolation. Defaults uses extrapolation.

  • extrapolation (Evaluator | Literal['bounds', 'exception', 'nan', 'none', 'periodic', 'zeros'] | None) – Controls the extrapolation mode for elements outside the domain range. By default uses the method defined in fd. See extrapolation to more information.

  • grid_points (Union[ArrayLike, Sequence[ArrayLike]] | None) – Grid of points where the functions are evaluated to obtain the discrete representation of the object to operate. If None the current grid_points are used to unificate the domain of the shifted data.

Returns:

Shifted functions.

Return type:

FDataGrid

Examples

>>> import numpy as np
>>> import skfda
>>>
>>> t = np.linspace(0, 1, 6)
>>> x = np.array([t, t**2, t**3])
>>> fd = skfda.FDataGrid(x, t)
>>> fd.domain_range[0]
(0.0, 1.0)
>>> fd.grid_points[0]
array([ 0. ,  0.2,  0.4,  0.6,  0.8,  1. ])
>>> fd.data_matrix[..., 0]
array([[ 0.   ,  0.2  ,  0.4  ,  0.6  ,  0.8  ,  1.   ],
       [ 0.   ,  0.04 ,  0.16 ,  0.36 ,  0.64 ,  1.   ],
       [ 0.   ,  0.008,  0.064,  0.216,  0.512,  1.   ]])

Shift all curves by the same amount:

>>> shifted = fd.shift(0.2)
>>> shifted.domain_range[0]
(0.0, 1.0)
>>> shifted.grid_points[0]
array([ 0. ,  0.2,  0.4,  0.6,  0.8,  1. ])
>>> shifted.data_matrix[..., 0]
array([[ 0.2  ,  0.4  ,  0.6  ,  0.8  ,  1.   ,  1.2  ],
       [ 0.04 ,  0.16 ,  0.36 ,  0.64 ,  1.   ,  1.36 ],
       [ 0.008,  0.064,  0.216,  0.512,  1.   ,  1.488]])

Different shift per curve:

>>> shifted = fd.shift([-0.2, 0.0, 0.2])
>>> shifted.domain_range[0]
(0.0, 1.0)
>>> shifted.grid_points[0]
array([ 0. ,  0.2,  0.4,  0.6,  0.8,  1. ])
>>> shifted.data_matrix[..., 0]
array([[-0.2  ,  0.   ,  0.2  ,  0.4  ,  0.6  ,  0.8  ],
       [ 0.   ,  0.04 ,  0.16 ,  0.36 ,  0.64 ,  1.   ],
       [ 0.008,  0.064,  0.216,  0.512,  1.   ,  1.488]])

It is possible to restrict the domain to prevent the need for extrapolations:

>>> shifted = fd.shift([-0.3, 0.1, 0.2], restrict_domain=True)
>>> shifted.domain_range[0]
(0.3, 0.8)
sum(*, axis=None, out=None, keepdims=False, skipna=False, min_count=0)[source]#

Compute the sum of all the samples.

Parameters:
  • axis (int | None) – Used for compatibility with numpy. Must be None or 0.

  • out (None) – Used for compatibility with numpy. Must be None.

  • keepdims (bool) – Used for compatibility with numpy. Must be False.

  • skipna (bool) – Wether the NaNs are ignored or not.

  • min_count (int) – Number of valid (non NaN) data to have in order for the a variable to not be NaN when skipna is True.

  • self (T) –

Returns:

A FDataGrid object with just one sample representing the sum of all the samples in the original object.

Return type:

T

Examples

>>> from skfda import FDataGrid
>>> data_matrix = [[0.5, 1, 2, .5], [1.5, 1, 4, .5]]
>>> FDataGrid(data_matrix).sum()
FDataGrid(
    array([[[ 2.],
            [ 2.],
            [ 6.],
            [ 1.]]]),
    ...)
take(indices, allow_fill=False, fill_value=None, axis=0)#

Take elements from an array.

Parameters:
  • indices (int | Sequence[int] | ndarray[Any, dtype[int64]]) – Indices to be taken.

  • allow_fill (bool) –

    How to handle negative values in indices. * False: negative values in indices indicate positional

    indices from the right (the default). This is similar to numpy.take().

    • True: negative values in indices indicate missing values. These values are set to fill_value. Any other negative values raise a ValueError.

  • fill_value (T | None) – Fill value to use for NA-indices when allow_fill is True. This may be None, in which case the default NA value for the type, self.dtype.na_value, is used. For many ExtensionArrays, there will be two representations of fill_value: a user-facing “boxed” scalar, and a low-level physical NA value. fill_value should be the user-facing version, and the implementation should handle translating that to the physical version for processing the take if necessary.

  • axis (int) – Parameter for compatibility with numpy. Must be always 0.

  • self (T) –

Returns:

FData

Raises:
  • IndexError – When the indices are out of bounds for the array.

  • ValueError – When indices contains negative values other than -1 and allow_fill is True.

Return type:

T

Notes

ExtensionArray.take is called by Series.__getitem__, .loc, iloc, when indices is a sequence of values. Additionally, it’s called by Series.reindex(), or any other method that causes realignment, with a fill_value.

See also

numpy.take pandas.api.extensions.take

to_basis(basis, **kwargs)[source]#

Return the basis representation of the object.

Parameters:
  • basis (Basis) – basis object in which the functional data are going to be represented.

  • kwargs (Any) – keyword arguments to be passed to FDataBasis.from_data().

Returns:

Basis representation of the funtional data object.

Return type:

FDataBasis

Examples

>>> import numpy as np
>>> import skfda
>>> t = np.linspace(0, 1, 5)
>>> x = np.sin(2 * np.pi * t) + np.cos(2 * np.pi * t) + 2
>>> x
array([ 3.,  3.,  1.,  1.,  3.])
>>> fd = FDataGrid(x, t)
>>> basis = skfda.representation.basis.FourierBasis(n_basis=3)
>>> fd_b = fd.to_basis(basis)
>>> fd_b.coefficients.round(2)
array([[ 2.  , 0.71, 0.71]])
to_grid(grid_points=None, *, sample_points=None)[source]#

Return the discrete representation of the object.

Parameters:
  • grid_points (Union[ArrayLike, Sequence[ArrayLike]] | None) – Points per axis where the function is going to be evaluated.

  • self (T) –

  • sample_points (Union[ArrayLike, Sequence[ArrayLike]] | None) –

Returns:

Discrete representation of the functional data object.

Return type:

T

to_numpy(dtype=None, copy=False, na_value=_NoDefault.no_default)#

Convert to a NumPy ndarray.

New in version 1.0.0.

This is similar to numpy.asarray(), but may provide additional control over how the conversion is done.

Parameters:
  • dtype (str or numpy.dtype, optional) – The dtype to pass to numpy.asarray().

  • copy (bool, default False) – Whether to ensure that the returned value is a not a view on another array. Note that copy=False does not ensure that to_numpy() is no-copy. Rather, copy=True ensure that a copy is made, even if not strictly necessary.

  • na_value (Any, optional) – The value to use for missing values. The default value depends on dtype and the type of the array.

Return type:

numpy.ndarray

tolist()#

Return a list of the values.

These are each a scalar type, which is a Python scalar (for str, int, float) or a pandas scalar (for Timestamp/Timedelta/Interval/Period)

Return type:

list

transpose(*axes)#

Return a transposed view on this array.

Because ExtensionArrays are always 1D, this is a no-op. It is included for compatibility with np.ndarray.

Parameters:

axes (int) –

Return type:

ExtensionArray

unique()#

Compute the ExtensionArray of unique values.

Returns:

uniques

Return type:

ExtensionArray

Parameters:

self (ExtensionArrayT) –

var()[source]#

Compute the variance of a set of samples in a FDataGrid object.

Returns:

A FDataGrid object with just one sample representing the variance of all the samples in the original FDataGrid object.

Parameters:

self (T) –

Return type:

T

view(dtype=None)#

Return a view on the array.

Parameters:

dtype (str, np.dtype, or ExtensionDtype, optional) – Default None.

Returns:

A view on the ExtensionArray’s data.

Return type:

ExtensionArray or np.ndarray