MCPcopy Index your code
hub / github.com/numpy/numpy / toflex

Method toflex

numpy/ma/core.py:6421–6479  ·  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

6419 raise NotImplementedError("MaskedArray.tofile() not implemented yet.")
6420
6421 def toflex(self):
6422 """
6423 Transforms a masked array into a flexible-type array.
6424
6425 The flexible type array that is returned will have two fields:
6426
6427 * the ``_data`` field stores the ``_data`` part of the array.
6428 * the ``_mask`` field stores the ``_mask`` part of the array.
6429
6430 Parameters
6431 ----------
6432 None
6433
6434 Returns
6435 -------
6436 record : ndarray
6437 A new flexible-type `ndarray` with two fields: the first element
6438 containing a value, the second element containing the corresponding
6439 mask boolean. The returned record shape matches self.shape.
6440
6441 Notes
6442 -----
6443 A side-effect of transforming a masked array into a flexible `ndarray` is
6444 that meta information (``fill_value``, ...) will be lost.
6445
6446 Examples
6447 --------
6448 >>> import numpy as np
6449 >>> x = np.ma.array([[1,2,3],[4,5,6],[7,8,9]], mask=[0] + [1,0]*4)
6450 >>> x
6451 masked_array(
6452 data=[[1, --, 3],
6453 [--, 5, --],
6454 [7, --, 9]],
6455 mask=[[False, True, False],
6456 [ True, False, True],
6457 [False, True, False]],
6458 fill_value=999999)
6459 >>> x.toflex()
6460 array([[(1, False), (2, True), (3, False)],
6461 [(4, True), (5, False), (6, True)],
6462 [(7, False), (8, True), (9, False)]],
6463 dtype=[('_data', '<i8'), ('_mask', '?')])
6464
6465 """
6466 # Get the basic dtype.
6467 ddtype = self.dtype
6468 # Make sure we have a mask
6469 _mask = self._mask
6470 if _mask is None:
6471 _mask = make_mask_none(self.shape, ddtype)
6472 # And get its dtype
6473 mdtype = self._mask.dtype
6474
6475 record = np.ndarray(shape=self.shape,
6476 dtype=[('_data', ddtype), ('_mask', mdtype)])
6477 record['_data'] = self._data
6478 record['_mask'] = self._mask

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