loupe.array#
- class loupe.array(object, dtype=None, mask=None, requires_grad=False)[source]#
Create a multidimensional array.
- Parameters:
object (array_like) – An array or other data type that can be interpreted as an array.
dtype (data-type, optional) – The desired data-type for the array. If not given, the type will be inferred from the supplied data object.
mask (array_like, optional) – Mask applied to the array where a True value indicates that the corresponding element of the array is invalid. Mask must have the same shape as the array and contain entries that are castable to bool. If None (default), the array is not masked.
requires_grad (bool, optional) – It True, gradients will be computed for this array. Default is False.
Attributes
The array's data.
Data type of the array's elements.
Gradient of the array.
Is
True
if gradients need to be computed for thisarray
,False
otherwise.Tuple of array dimensions.
Methods
backward
(grad)Compute the gradient of the array.
flatten
([apply_mask])Return the array flattened into one dimension.
getdata
([copy, dtype])Return the array's data.
grad_flatten
([apply_mask])Zero the array gradient.
- backward(grad)[source]#
Compute the gradient of the array.
- Parameters:
grad (array_like) – Gradient with respect to the array.
- property data#
The array’s data.
- Returns:
data
- Return type:
ndarray
- property dtype#
Data type of the array’s elements.
- flatten(apply_mask=False)[source]#
Return the array flattened into one dimension.
- Parameters:
apply_mask (bool, optional) – If True, only non-masked data is returned. Default is False.
- getdata(copy=False, dtype=None)#
Return the array’s data.
- Parameters:
copy (bool, optional) – Whether to force a copy of the underlying data to be returned.
dtype (type or numpy dtype, optional) – The dtype of the returned data.
- property grad#
Gradient of the array.
This attribute is zero by default and is only computed when
requires_grad
is True andbackward()
is called.- Returns:
grad
- Return type:
ndarray
- property mask#
- property ndim#
- property shape#
Tuple of array dimensions.
- property strides#