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

Function filled

numpy/ma/core.py:587–641  ·  view source on GitHub ↗

Return input as an array with masked data replaced by a fill value. If `a` is not a `MaskedArray`, `a` itself is returned. If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to ``a.fill_value``. Parameters ---------- a : MaskedArray or array_like

(a, fill_value=None)

Source from the content-addressed store, hash-verified

585
586
587def filled(a, fill_value=None):
588 """
589 Return input as an array with masked data replaced by a fill value.
590
591 If `a` is not a `MaskedArray`, `a` itself is returned.
592 If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
593 ``a.fill_value``.
594
595 Parameters
596 ----------
597 a : MaskedArray or array_like
598 An input object.
599 fill_value : array_like, optional.
600 Can be scalar or non-scalar. If non-scalar, the
601 resulting filled array should be broadcastable
602 over input array. Default is None.
603
604 Returns
605 -------
606 a : ndarray
607 The filled array.
608
609 See Also
610 --------
611 compressed
612
613 Examples
614 --------
615 >>> x = np.ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
616 ... [1, 0, 0],
617 ... [0, 0, 0]])
618 >>> x.filled()
619 array([[999999, 1, 2],
620 [999999, 4, 5],
621 [ 6, 7, 8]])
622 >>> x.filled(fill_value=333)
623 array([[333, 1, 2],
624 [333, 4, 5],
625 [ 6, 7, 8]])
626 >>> x.filled(fill_value=np.arange(3))
627 array([[0, 1, 2],
628 [0, 4, 5],
629 [6, 7, 8]])
630
631 """
632 if hasattr(a, 'filled'):
633 return a.filled(fill_value)
634
635 elif isinstance(a, ndarray):
636 # Should we check for contiguity ? and a.flags['CONTIGUOUS']:
637 return a
638 elif isinstance(a, dict):
639 return np.array(a, 'O')
640 else:
641 return np.array(a)
642
643
644def get_masked_subclass(*arrays):

Callers 15

__setattr__Method · 0.90
test_testBasic1dMethod · 0.90
test_testBasic2dMethod · 0.90
test_testAddSumProdMethod · 0.90
test_testCopySizeMethod · 0.90
test_testMaskedMethod · 0.90
test_basic1dMethod · 0.90
test_basic2dMethod · 0.90
test_maskedelementMethod · 0.90
test_copyMethod · 0.90
test_addsumprodMethod · 0.90

Calls 1

filledMethod · 0.45

Tested by 15

test_testBasic1dMethod · 0.72
test_testBasic2dMethod · 0.72
test_testAddSumProdMethod · 0.72
test_testCopySizeMethod · 0.72
test_testMaskedMethod · 0.72
test_basic1dMethod · 0.72
test_basic2dMethod · 0.72
test_maskedelementMethod · 0.72
test_copyMethod · 0.72
test_addsumprodMethod · 0.72