numpy.ma.MaskedArray.view

MaskedArray.view(dtype=None, type=None)

New view of array with the same data.

Parameters:

dtype : data-type

Data-type descriptor of the returned view, e.g. float32 or int16.

type : python type

Type of the returned view, e.g. ndarray or matrix.

Examples

>>> x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)])

Viewing array data using a different type and dtype:

>>> y = x.view(dtype=np.int16, type=np.matrix)
>>> print y.dtype
int16
>>> print type(y)
<class 'numpy.core.defmatrix.matrix'>

Using a view to convert an array to a record array:

>>> z = x.view(np.recarray)
>>> z.a
array([1], dtype=int8)

Views share data:

>>> x[0] = (9, 10)
>>> z[0]
(9, 10)

Previous topic

numpy.ma.MaskedArray.__oct__

Next topic

numpy.ma.MaskedArray.astype

This Page

Quick search