skfolio.containers.Field3D#
- class skfolio.containers.Field3D(values, third_axis_name, third_axis_labels, third_axis_groups=None, *, inactive_policy=MISSING)[source]#
Numeric 3D field with axes (observations, assets, third_axis).
Use this field for homogeneous tensors (e.g. factor exposures). The third-axis metadata is stored on the field. The array is stored physically in 3D so that operations along any axis remain vectorized and avoid stacking many 2D arrays which is expensive for large panels. When you need repeated tensor operations, prefer a
Field3Dinstead of multipleField2D.- Parameters:
- valuesndarray of shape
(n_observations, n_assets, n_third_axis) Numeric 3D values. Object dtype is rejected.
- third_axis_namestr
Name describing what the third axis represents (e.g.
factor).- third_axis_labelsndarray of shape (n_third_axis,)
Labels for entries along the third axis such as factor names (
size,momentum). Labels must be unique.- third_axis_groupsndarray of shape (n_third_axis,), optional
Optional group label for each third-axis entry such as factor families (e.g.
style,industry,country).
- valuesndarray of shape
- Attributes:
dtypeDtype of the underlying values.
- inactive_policy
is_3dWhether or not the field is a 3D field.
is_categoricalWhether or not the field is a categorical field.
missing_maskReturn a boolean mask indicating missing entries.
n_assetsNumber of assets.
n_observationsNumber of observations.
ndimNumber of dimensions of the underlying values.
shapeShape of the underlying values.
- third_axis_groups
- third_axis_labels
- third_axis_name
- values
Methods
copy(*[, deep])Return a copy of the field.
with_values(values)Return a field of the same type with replacement values.
- copy(*, deep=False)#
Return a copy of the field.
- Parameters:
- deepbool, default=False
If
True, copy NumPy arrays stored by the field. IfFalse, reuse the same array objects.
- Returns:
- fieldBaseField
Field instance of the same concrete class.
- property dtype#
Dtype of the underlying values.
- property is_3d#
Whether or not the field is a 3D field.
- property is_categorical#
Whether or not the field is a categorical field.
- property missing_mask#
Return a boolean mask indicating missing entries.
- Returns:
- maskndarray of bool
Boolean array with the same shape as
values. Entries areTruewherevaluesis NaN for floating-point fields andFalseelsewhere. Non-floating fields without a missing-value convention return an all-Falsemask; subclasses override this method when they define their own convention.
- property n_assets#
Number of assets.
- property n_observations#
Number of observations.
- property ndim#
Number of dimensions of the underlying values.
- property shape#
Shape of the underlying values.
- with_values(values)#
Return a field of the same type with replacement values.
Metadata arrays are reused. The replacement values are validated by the concrete field class constructor.
- Parameters:
- valuesarray-like
Replacement field values.
- Returns:
- fieldBaseField
Field instance of the same concrete class.