dipy logo

Site Navigation

NIPY Community

dipy.reconst.maskedview

Class to allow masked view of data array

class dipy.reconst.maskedview.MaskedView(mask, data, fill_value=None)

An interface to allow the user to interact with a data array as if it is a container with the same shape as mask. The contents of data are mapped to the nonzero elements of mask, where mask is zero fill_value is used.

Examples

>>> mask = np.array([[True, False, True],[False, True, False]])
>>> data = np.arange(2*3*4)
>>> data.shape = (2, 3, 4)
>>> mv = MaskedView(mask, data[mask], fill_value=10)
>>> mv.shape
(2, 3, 4)
>>> data[0, 0, :]
array([0, 1, 2, 3])
>>> mv[0, 1]
array([10, 10, 10, 10])
>>> mv[:,:,0]
array([[ 0, 10,  8],
       [10, 16, 10]])

Methods

copy() Returns a copy of the MaskedView. Copies the underlying data array.
filled([fill_value]) Returns an ndarray copy of itself.
get_size() Returns the number of non-empty values in MaskedView, ie where
copy()

Returns a copy of the MaskedView. Copies the underlying data array.

filled(fill_value=None)

Returns an ndarray copy of itself. Where mask is zero, fill_value is used (self.fill_value defult).

Parameters :

fill_value : :

Value to be used in place of data where mask is 0.

get_size()

Returns the number of non-empty values in MaskedView, ie where mask > 0.