numpy.ma.reshape#

ma.reshape(a, new_shape, order='C')[源代码]#

返回一个包含相同数据但具有新形状的数组.

请参阅 MaskedArray.reshape 以获取完整文档.

参见

MaskedArray.reshape

等效函数

示例

重塑一个一维数组:

>>> a = np.ma.array([1, 2, 3, 4])
>>> np.ma.reshape(a, (2, 2))
masked_array(
  data=[[1, 2],
        [3, 4]],
  mask=False,
  fill_value=999999)

重塑一个二维数组:

>>> b = np.ma.array([[1, 2], [3, 4]])
>>> np.ma.reshape(b, (1, 4))
masked_array(data=[[1, 2, 3, 4]],
             mask=False,
       fill_value=999999)

使用掩码重塑一维数组:

>>> c = np.ma.array([1, 2, 3, 4], mask=[False, True, False, False])
>>> np.ma.reshape(c, (2, 2))
masked_array(
  data=[[1, --],
        [3, 4]],
  mask=[[False,  True],
        [False, False]],
  fill_value=999999)