traits.trait_numeric
Module¶
Trait definitions related to the numpy library.
Classes¶

class
traits.trait_numeric.
AbstractArray
(dtype=None, shape=None, value=None, coerce=False, typecode=None, *, casting='unsafe', **metadata)[source]¶ Bases:
traits.trait_type.TraitType
Abstract base class for defining numpybased arrays.

class
traits.trait_numeric.
Array
(dtype=None, shape=None, value=None, typecode=None, *, casting='unsafe', **metadata)[source]¶ Bases:
traits.trait_numeric.AbstractArray
A trait type whose value must be a NumPy array.
An Array trait allows only upcasting of assigned values that are already numpy arrays. It automatically casts tuples and lists of the right shape to the specified dtype (just like numpy’s array does).
The default value is either the value argument or
zeros(min(shape))
, wheremin(shape)
refers to the minimum shape allowed by the array. If shape is not specified, the minimum shape is (0,). Parameters
dtype (a numpy dtype (e.g., int32)) – The type of elements in the array; if omitted, no typechecking is performed on assigned values.
shape (a tuple) – Describes the required shape of any assigned value. Wildcards and ranges are allowed. The value None within the shape tuple means that the corresponding dimension is not checked. (For example,
shape=(None,3)
means that the first dimension can be any size, but the second must be 3.) A twoelement tuple within the shape tuple means that the dimension must be in the specified range. The second element can be None to indicate that there is no upper bound. (For example,shape=((3,5),(2,None))
means that the first dimension must be in the range 3 to 5 (inclusive), and the second dimension must be at least 2.)value (numpy array) – A default value for the array.
casting (str) –
Casting rule for the array’s dtype. If
dtype
is set, a value can only be assigned if it passes the casting rule. Values can be:”no”: No casting is allowed
”equiv”: Only byteorder changes are allowed
”safe”: Only allow casting that fully preserves values (e.g. “float32” to “float64”)
”samekind”: Only safe casts or casts within a kind (e.g. “float64” to “float32”) are allowed
”unsafe”: Any casting is allowed
Default is “unsafe”.

class
traits.trait_numeric.
ArrayOrNone
(*args, **metadata)[source]¶ Bases:
traits.trait_numeric.CArray
A coercing trait whose value may be either a NumPy array or None.
This trait is designed to avoid the comparison issues with numpy arrays that can arise from the use of constructs like Either(None, Array).
The default value is None.

class
traits.trait_numeric.
CArray
(dtype=None, shape=None, value=None, typecode=None, *, casting='unsafe', **metadata)[source]¶ Bases:
traits.trait_numeric.AbstractArray
A coercing trait type whose value is a NumPy array.
The trait returned by CArray() is similar to that returned by Array(), except that it allows both upcasting and downcasting of assigned values that are already numpy arrays. It automatically casts tuples and lists of the right shape to the specified dtype (just like numpy’s array does).
The default value is either the value argument or
zeros(min(shape))
, wheremin(shape)
refers to the minimum shape allowed by the array. If shape is not specified, the minimum shape is (0,). Parameters
dtype (a numpy dtype (e.g., int32)) – The type of elements in the array.
shape (a tuple) – Describes the required shape of any assigned value. Wildcards and ranges are allowed. The value None within the shape tuple means that the corresponding dimension is not checked. (For example,
shape=(None,3)
means that the first dimension can be any size, but the second must be 3.) A twoelement tuple within the shape tuple means that the dimension must be in the specified range. The second element can be None to indicate that there is no upper bound. (For example,shape=((3,5),(2,None))
means that the first dimension must be in the range 3 to 5 (inclusive), and the second dimension must be at least 2.)value (numpy array) – A default value for the array.
casting (str) –
Casting rule for the array’s dtype. If
dtype
is set, a value can only be assigned if it passes the casting rule. Values can be:”no”: No casting is allowed
”equiv”: Only byteorder changes are allowed
”safe”: Only allow casting that fully preserves values (e.g. “float32” to “float64”)
”samekind”: Only safe casts or casts within a kind (e.g. “float64” to “float32”) are allowed
”unsafe”: Any casting is allowed
Default is “unsafe”.