Here are the examples of the python api numpy.ma.MaskedArray taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
50 Examples
3
View Complete Implementation : test_mrecords.py
Copyright MIT License
Author : abhisuri97
Copyright MIT License
Author : abhisuri97
def test_view_simple_dtype(self):
(mrec, a, b, arr) = self.data
ntype = (np.float, 2)
test = mrec.view(ntype)
self.astertTrue(isinstance(test, ma.MaskedArray))
astert_equal(test, np.array(list(zip(a, b)), dtype=np.float))
self.astertTrue(test[3, 1] is ma.masked)
3
View Complete Implementation : test_recfunctions.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_join_subdtype(self):
# tests the bug in https://stackoverflow.com/q/44769632/102441
from numpy.lib import recfunctions as rfn
foo = np.array([(1,)],
dtype=[('key', int)])
bar = np.array([(1, np.array([1,2,3]))],
dtype=[('key', int), ('value', 'uint16', 3)])
res = join_by('key', foo, bar)
astert_equal(res, bar.view(ma.MaskedArray))
3
View Complete Implementation : test_mrecords.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_view_simple_dtype(self):
(mrec, a, b, arr) = self.data
ntype = (float, 2)
test = mrec.view(ntype)
astert_(isinstance(test, ma.MaskedArray))
astert_equal(test, np.array(list(zip(a, b)), dtype=float))
astert_(test[3, 1] is ma.masked)
3
View Complete Implementation : test_regression.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_mask_not_backmangled(self):
# See gh-10314. Test case taken from gh-3140.
a = np.ma.MaskedArray([1., 2.], mask=[False, False])
astert_(a.mask.shape == (2,))
b = np.tile(a, (2, 1))
# Check that the above no longer changes a.shape to (1, 2)
astert_(a.mask.shape == (2,))
astert_(b.shape == (2, 2))
astert_(b.mask.shape == (2, 2))
3
View Complete Implementation : test_utils.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_masked_nan_inf(self):
# Regression test for gh-11121
a = np.ma.MaskedArray([3., 4., 6.5], mask=[False, True, False])
b = np.array([3., np.nan, 6.5])
self._test_equal(a, b)
self._test_equal(b, a)
a = np.ma.MaskedArray([3., 4., 6.5], mask=[True, False, False])
b = np.array([np.inf, 4., 6.5])
self._test_equal(a, b)
self._test_equal(b, a)
3
View Complete Implementation : test_pilutil.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def test_bytescale_mask(self):
a = np.ma.MaskedArray(data=[1, 2, 3], mask=[False, False, True])
with suppress_warnings() as sup:
sup.filter(DeprecationWarning)
actual = misc.bytescale(a)
expected = [0, 255, 3]
astert_equal(expected, actual)
astert_mask_equal(a.mask, actual.mask)
astert_(isinstance(actual, np.ma.MaskedArray))
3
View Complete Implementation : fixes.py
Copyright MIT License
Author : alvarob96
Copyright MIT License
Author : alvarob96
def __getstate__(self):
"""Return the internal state of the masked array, for pickling
purposes.
"""
cf = 'CF'[self.flags.fnc]
data_state = super(np.ma.MaskedArray, self).__reduce__()[2]
return data_state + (np.ma.getmaskarray(self).tostring(cf),
self._fill_value)
3
View Complete Implementation : stats.py
Copyright MIT License
Author : Ardavans
Copyright MIT License
Author : Ardavans
def cov(a):
# return np.cov(a,rowvar=0,bias=1)
mu = a.mean(0)
if isinstance(a,np.ma.MaskedArray):
return np.ma.dot(a.T,a)/a.count(0)[0] - np.ma.outer(mu,mu)
else:
return a.T.dot(a)/a.shape[0] - np.outer(mu,mu)
3
View Complete Implementation : vop.py
Copyright GNU General Public License v3.0
Author : asarnow
Copyright GNU General Public License v3.0
Author : asarnow
def normalize(vol, ref=None, return_stats=False):
volm = vol.view(ma.MaskedArray)
sz = volm.shape[0]
rng = np.arange(-sz/2, sz)
x, y, z = np.meshgrid(rng, rng, rng)
r2 = x**2 + y**2 + z**2
mask = r2 > sz**2
volm.mask = mask
if ref is not None:
ref = ref.view(ma.MaskedArray)
ref.mask = mask
sigma = np.std(ref)
mu = np.mean(ref)
else:
sigma = np.std(volm)
mu = np.mean(volm)
if return_stats:
return (vol - mu) / sigma, mu, sigma
return (vol - mu) / sigma
3
View Complete Implementation : resampling.py
Copyright MIT License
Author : CCI-Tools
Copyright MIT License
Author : CCI-Tools
def _get_mask(src):
if isinstance(src, np.ma.MaskedArray):
mask = np.ma.getmask(src)
if mask is not np.ma.nomask:
return mask, True
return _NOMASK2D, False