numpy.ma.MaskedArray.view¶
method
-
MaskedArray.
view
(self, dtype=None, type=None, fill_value=None)[source]¶ Return a view of the MaskedArray data.
- Parameters
- dtypedata-type or ndarray sub-class, optional
Data-type descriptor of the returned view, e.g., float32 or int16. The default, None, results in the view having the same data-type as a. As with
ndarray.view
, dtype can also be specified as an ndarray sub-class, which then specifies the type of the returned object (this is equivalent to setting thetype
parameter).- typePython type, optional
Type of the returned view, either ndarray or a subclass. The default None results in type preservation.
- fill_valuescalar, optional
The value to use for invalid entries (None by default). If None, then this argument is inferred from the passed
dtype
, or in its absence the original array, as discussed in the notes below.
See also
numpy.ndarray.view
Equivalent method on ndarray object.
Notes
a.view()
is used two different ways:a.view(some_dtype)
ora.view(dtype=some_dtype)
constructs a view of the array’s memory with a different data-type. This can cause a reinterpretation of the bytes of memory.a.view(ndarray_subclass)
ora.view(type=ndarray_subclass)
just returns an instance of ndarray_subclass that looks at the same array (same shape, dtype, etc.) This does not cause a reinterpretation of the memory.If
fill_value
is not specified, butdtype
is specified (and is not an ndarray sub-class), thefill_value
of the MaskedArray will be reset. If neitherfill_value
nordtype
are specified (or ifdtype
is an ndarray sub-class), then the fill value is preserved. Finally, iffill_value
is specified, butdtype
is not, the fill value is set to the specified value.For
a.view(some_dtype)
, ifsome_dtype
has a different number of bytes per entry than the previous dtype (for example, converting a regular array to a structured array), then the behavior of the view cannot be predicted just from the superficial appearance ofa
(shown byprint(a)
). It also depends on exactly howa
is stored in memory. Therefore ifa
is C-ordered versus fortran-ordered, versus defined as a slice or transpose, etc., the view may give different results.