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

Function filled

numpy/ma/core.py:631–690  ·  view source on GitHub ↗

Return input as an `~numpy.ndarray`, with masked values replaced by `fill_value`. If `a` is not a `MaskedArray`, `a` itself is returned. If `a` is a `MaskedArray` with no masked values, then ``a.data`` is returned. If `a` is a `MaskedArray` and `fill_value` is None, `fill_v

(a, fill_value=None)

Source from the content-addressed store, hash-verified

629
630
631def filled(a, fill_value=None):
632 """
633 Return input as an `~numpy.ndarray`, with masked values replaced by
634 `fill_value`.
635
636 If `a` is not a `MaskedArray`, `a` itself is returned.
637 If `a` is a `MaskedArray` with no masked values, then ``a.data`` is
638 returned.
639 If `a` is a `MaskedArray` and `fill_value` is None, `fill_value` is set to
640 ``a.fill_value``.
641
642 Parameters
643 ----------
644 a : MaskedArray or array_like
645 An input object.
646 fill_value : array_like, optional.
647 Can be scalar or non-scalar. If non-scalar, the
648 resulting filled array should be broadcastable
649 over input array. Default is None.
650
651 Returns
652 -------
653 a : ndarray
654 The filled array.
655
656 See Also
657 --------
658 compressed
659
660 Examples
661 --------
662 >>> import numpy as np
663 >>> import numpy.ma as ma
664 >>> x = ma.array(np.arange(9).reshape(3, 3), mask=[[1, 0, 0],
665 ... [1, 0, 0],
666 ... [0, 0, 0]])
667 >>> x.filled()
668 array([[999999, 1, 2],
669 [999999, 4, 5],
670 [ 6, 7, 8]])
671 >>> x.filled(fill_value=333)
672 array([[333, 1, 2],
673 [333, 4, 5],
674 [ 6, 7, 8]])
675 >>> x.filled(fill_value=np.arange(3))
676 array([[0, 1, 2],
677 [0, 4, 5],
678 [6, 7, 8]])
679
680 """
681 if hasattr(a, 'filled'):
682 return a.filled(fill_value)
683
684 elif isinstance(a, ndarray):
685 # Should we check for contiguity ? and a.flags['CONTIGUOUS']:
686 return a
687 elif isinstance(a, dict):
688 return np.array(a, 'O')

Callers 15

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…