numpy.ma.masked_array.reshape#
method
- ma.masked_array.reshape(*s, **kwargs)[source]#
Returns a reshaped masked array without changing its data.
Returns a masked array containing the same data, but with a new shape. The result is a new view object if possible; otherwise, it will be a copy.
- Parameters:
- shapeint or tuple of ints
The new shape should be compatible with the original shape. If an integer is supplied, then the result will be a 1-D array of that length.
- order{‘C’, ‘F’, ‘A’}, optional
Determines whether the array data should be viewed as in C (row-major) or FORTRAN (column-major) order. ‘A’ uses FORTRAN order for Fortran-contiguous data, C order otherwise.
- copybool, optional
If
True, the data and mask are copied. IfNone, a copy will only be made if it’s required byorder. IfFalse, it raises aValueErrorif a copy cannot be avoided. Default:None.
- Returns:
- reshaped_arrayMaskedArray
This will be a new view object if possible; otherwise, it will be a copy.
See also
reshapeEquivalent function in the masked array module.
numpy.ndarray.reshapeEquivalent method on ndarray object.
numpy.reshapeEquivalent function in the NumPy module.
Notes
By default, the reshaping operation will make a copy if a view with different strides is not possible. To ensure a view, pass
copy=False.Examples
>>> import numpy as np >>> x = np.ma.array([[1,2],[3,4]], mask=[1,0,0,1]) >>> x masked_array( data=[[--, 2], [3, --]], mask=[[ True, False], [False, True]], fill_value=999999) >>> x = x.reshape((4,1)) >>> x masked_array( data=[[--], [2], [3], [--]], mask=[[ True], [False], [False], [ True]], fill_value=999999)