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

data

The array's data.

dtype

Data type of the array's elements.

grad

Gradient of the array.

mask

ndim

requires_grad

Is True if gradients need to be computed for this array, False otherwise.

shape

Tuple of array dimensions.

strides

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_grad()

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 and backward() is called.

Returns:

grad

Return type:

ndarray

grad_flatten(apply_mask=False)[source]#
property mask#
property ndim#
property requires_grad#

Is True if gradients need to be computed for this array, False otherwise.

property shape#

Tuple of array dimensions.

property strides#
zero_grad()[source]#

Zero the array gradient.