MCPcopy Create free account
hub / github.com/numpy/numpy / toflex

Method toflex

numpy/ma/core.py:6223–6280  ·  view source on GitHub ↗

Transforms a masked array into a flexible-type array. The flexible type array that is returned will have two fields: * the ``_data`` field stores the ``_data`` part of the array. * the ``_mask`` field stores the ``_mask`` part of the array. Parameters

(self)

Source from the content-addressed store, hash-verified

6221 raise NotImplementedError("MaskedArray.tofile() not implemented yet.")
6222
6223 def toflex(self):
6224 """
6225 Transforms a masked array into a flexible-type array.
6226
6227 The flexible type array that is returned will have two fields:
6228
6229 * the ``_data`` field stores the ``_data`` part of the array.
6230 * the ``_mask`` field stores the ``_mask`` part of the array.
6231
6232 Parameters
6233 ----------
6234 None
6235
6236 Returns
6237 -------
6238 record : ndarray
6239 A new flexible-type `ndarray` with two fields: the first element
6240 containing a value, the second element containing the corresponding
6241 mask boolean. The returned record shape matches self.shape.
6242
6243 Notes
6244 -----
6245 A side-effect of transforming a masked array into a flexible `ndarray` is
6246 that meta information (``fill_value``, ...) will be lost.
6247
6248 Examples
6249 --------
6250 >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
6251 >>> x
6252 masked_array(
6253 data=[[1, --, 3],
6254 [--, 5, --],
6255 [7, --, 9]],
6256 mask=[[False, True, False],
6257 [ True, False, True],
6258 [False, True, False]],
6259 fill_value=999999)
6260 >>> x.toflex()
6261 array([[(1, False), (2, True), (3, False)],
6262 [(4, True), (5, False), (6, True)],
6263 [(7, False), (8, True), (9, False)]],
6264 dtype=[('_data', '<i8'), ('_mask', '?')])
6265
6266 """
6267 # Get the basic dtype.
6268 ddtype = self.dtype
6269 # Make sure we have a mask
6270 _mask = self._mask
6271 if _mask is None:
6272 _mask = make_mask_none(self.shape, ddtype)
6273 # And get its dtype
6274 mdtype = self._mask.dtype
6275
6276 record = np.ndarray(shape=self.shape,
6277 dtype=[('_data', ddtype), ('_mask', mdtype)])
6278 record['_data'] = self._data
6279 record['_mask'] = self._mask
6280 return record

Callers 2

test_toflexMethod · 0.80
test_fromflexMethod · 0.80

Calls 1

make_mask_noneFunction · 0.85

Tested by 2

test_toflexMethod · 0.64
test_fromflexMethod · 0.64