当前位置: 首页>>代码示例>>Python>>正文


Python ma.masked_all方法代码示例

本文整理汇总了Python中numpy.ma.masked_all方法的典型用法代码示例。如果您正苦于以下问题:Python ma.masked_all方法的具体用法?Python ma.masked_all怎么用?Python ma.masked_all使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.ma的用法示例。


在下文中一共展示了ma.masked_all方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_constructor_maskedarray_hardened

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_maskedarray_hardened(self):
        # Check numpy masked arrays with hard masks -- from GH24574
        mat_hard = ma.masked_all((2, 2), dtype=float).harden_mask()
        result = pd.DataFrame(mat_hard, columns=['A', 'B'], index=[1, 2])
        expected = pd.DataFrame({
            'A': [np.nan, np.nan],
            'B': [np.nan, np.nan]},
            columns=['A', 'B'],
            index=[1, 2],
            dtype=float)
        tm.assert_frame_equal(result, expected)
        # Check case where mask is hard but no data are masked
        mat_hard = ma.ones((2, 2), dtype=float).harden_mask()
        result = pd.DataFrame(mat_hard, columns=['A', 'B'], index=[1, 2])
        expected = pd.DataFrame({
            'A': [1.0, 1.0],
            'B': [1.0, 1.0]},
            columns=['A', 'B'],
            index=[1, 2],
            dtype=float)
        tm.assert_frame_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_constructors.py

示例2: make_mosaic

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def make_mosaic(images, num_rows, num_cols, border=1, class_names=None):
    num_images = len(images)
    image_shape = images.shape[1:]
    mosaic = ma.masked_all(
            (num_rows * image_shape[0] + (num_rows - 1) * border,
             num_cols * image_shape[1] + (num_cols - 1) * border),
            dtype=np.float32)
    paddedh = image_shape[0] + border
    paddedw = image_shape[1] + border
    for image_arg in range(num_images):
        row = int(np.floor(image_arg / num_cols))
        col = image_arg % num_cols
        image = np.squeeze(images[image_arg])
        image_shape = image.shape
        mosaic[row * paddedh:row * paddedh + image_shape[0],
               col * paddedw:col * paddedw + image_shape[1]] = image
    return mosaic 
开发者ID:oarriaga,项目名称:face_classification,代码行数:19,代码来源:visualizer.py

示例3: make_mosaic

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def make_mosaic(images, num_rows, num_cols, border=1, class_names=None):
    num_images = len(images)
    image_shape = images.shape[1:]
    mosaic = ma.masked_all((num_rows * image_shape[0] + (num_rows - 1) * border,
                            num_cols * image_shape[1] + (num_cols - 1) * border),
                            dtype=np.float32)
    paddedh = image_shape[0] + border
    paddedw = image_shape[1] + border
    for image_arg in range(num_images):
        row = int(np.floor(image_arg / num_cols))
        col = image_arg % num_cols
        image = np.squeeze(images[image_arg])
        image_shape = image.shape
        mosaic[row * paddedh:row * paddedh + image_shape[0],
               col * paddedw:col * paddedw + image_shape[1]] = image
    return mosaic 
开发者ID:petercunha,项目名称:Emotion,代码行数:18,代码来源:visualizer.py

示例4: test_constructor_maskedarray_hardened

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_maskedarray_hardened(self):
        # Check numpy masked arrays with hard masks -- from GH24574
        data = ma.masked_all((3, ), dtype=float).harden_mask()
        result = pd.Series(data)
        expected = pd.Series([nan, nan, nan])
        tm.assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_constructors.py

示例5: test_constructor_maskedarray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_maskedarray(self):
        self._check_basic_constructor(ma.masked_all)

        # Check non-masked values
        mat = ma.masked_all((2, 3), dtype=float)
        mat[0, 0] = 1.0
        mat[1, 2] = 2.0
        frame = DataFrame(mat, columns=['A', 'B', 'C'], index=[1, 2])
        assert 1.0 == frame['A'][1]
        assert 2.0 == frame['C'][2]

        # what is this even checking??
        mat = ma.masked_all((2, 3), dtype=float)
        frame = DataFrame(mat, columns=['A', 'B', 'C'], index=[1, 2])
        assert np.all(~np.asarray(frame == frame)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:test_constructors.py

示例6: _add_row_block

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def _add_row_block(self):
        """add a block of rows to the data array
        """
        block = ma.masked_all((self._row_block_size,), dtype=self.dtype)
        
        self._set_data(ma.append(self._data, block)) 
开发者ID:vicariousinc,项目名称:pixelworld,代码行数:8,代码来源:datatypes.py

示例7: make_mosaic

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def make_mosaic(imgs, nrows, ncols, border=1):
    """
    Given a set of images with all the same shape, makes a
    mosaic with nrows and ncols
    """
    nimgs = imgs.shape[0]
    imshape = imgs.shape[1:]

    mosaic = ma.masked_all((nrows * imshape[0] + (nrows - 1) * border,
                            ncols * imshape[1] + (ncols - 1) * border),
                           dtype=np.float32)

    paddedh = imshape[0] + border
    paddedw = imshape[1] + border
    for i in xrange(nimgs):
        row = int(np.floor(i / ncols))
        col = i % ncols

        mosaic[row * paddedh:row * paddedh + imshape[0],
        col * paddedw:col * paddedw + imshape[1]] = imgs[i]
    return mosaic

    
# -----------------------------------------------------------------------------

# https://blog.keras.io/
# how-convolutional-neural-networks-see-the-world.html

# http://ankivil.com/visualizing-deep-neural-networks-classes-and-features/

# ----------------------------------------------------------------------------- 
开发者ID:mani-shailesh,项目名称:satimage,代码行数:33,代码来源:util.py

示例8: draw

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def draw(self, size=1, spaces=None):
        """
        Draw samples from the transdimensional distribution.
        """
        if spaces is not None:
            if len(spaces) != size:
                raise ValueError('Sample size inconsistent with number of spaces saved')
            space_inds = np.empty(size)
            for space_id, space in enumerate(self.spaces):
                subspace = np.all(spaces == space, axis=1)
                space_inds[subspace] = space_id

        else:
            # Draws spaces randomly with the assigned weights
            cumulative_weights = np.cumsum(np.exp(self._logweights))
            space_inds = np.searchsorted(cumulative_weights, np.random.rand(size))

        draws = ma.masked_all((size, self._max_ndim))
        for space_id in range(len(self.spaces)):
            sel = space_inds == space_id
            n_fixedd = np.count_nonzero(sel)
            if n_fixedd > 0:
                # Populate only the valid entries for this parameter space
                draws[np.ix_(sel, self._spaces[space_id])] = self.kdes[space_id].draw(n_fixedd)

        return draws 
开发者ID:bfarr,项目名称:kombine,代码行数:28,代码来源:clustered_kde.py

示例9: test_constructor_mrecarray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_mrecarray(self):
        # Ensure mrecarray produces frame identical to dict of masked arrays
        # from GH3479

        assert_fr_equal = functools.partial(tm.assert_frame_equal,
                                            check_index_type=True,
                                            check_column_type=True,
                                            check_frame_type=True)
        arrays = [
            ('float', np.array([1.5, 2.0])),
            ('int', np.array([1, 2])),
            ('str', np.array(['abc', 'def'])),
        ]
        for name, arr in arrays[:]:
            arrays.append(('masked1_' + name,
                           np.ma.masked_array(arr, mask=[False, True])))
        arrays.append(('masked_all', np.ma.masked_all((2,))))
        arrays.append(('masked_none',
                       np.ma.masked_array([1.0, 2.5], mask=False)))

        # call assert_frame_equal for all selections of 3 arrays
        for comb in itertools.combinations(arrays, 3):
            names, data = zip(*comb)
            mrecs = ma.mrecords.fromarrays(data, names=names)

            # fill the comb
            comb = {k: (v.filled() if hasattr(v, 'filled') else v)
                    for k, v in comb}

            expected = DataFrame(comb, columns=names)
            result = DataFrame(mrecs)
            assert_fr_equal(result, expected)

            # specify columns
            expected = DataFrame(comb, columns=names[::-1])
            result = DataFrame(mrecs, columns=names[::-1])
            assert_fr_equal(result, expected)

            # specify index
            expected = DataFrame(comb, columns=names, index=[1, 2])
            result = DataFrame(mrecs, index=[1, 2])
            assert_fr_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:44,代码来源:test_constructors.py

示例10: test_constructor_mrecarray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_mrecarray(self):
        # Ensure mrecarray produces frame identical to dict of masked arrays
        # from GH3479

        assert_fr_equal = functools.partial(tm.assert_frame_equal,
                                            check_index_type=True,
                                            check_column_type=True,
                                            check_frame_type=True)
        arrays = [
            ('float', np.array([1.5, 2.0])),
            ('int', np.array([1, 2])),
            ('str', np.array(['abc', 'def'])),
        ]
        for name, arr in arrays[:]:
            arrays.append(('masked1_' + name,
                           np.ma.masked_array(arr, mask=[False, True])))
        arrays.append(('masked_all', np.ma.masked_all((2,))))
        arrays.append(('masked_none',
                       np.ma.masked_array([1.0, 2.5], mask=False)))

        # call assert_frame_equal for all selections of 3 arrays
        for comb in itertools.combinations(arrays, 3):
            names, data = zip(*comb)
            mrecs = mrecords.fromarrays(data, names=names)

            # fill the comb
            comb = {k: (v.filled() if hasattr(v, 'filled') else v)
                    for k, v in comb}

            expected = DataFrame(comb, columns=names)
            result = DataFrame(mrecs)
            assert_fr_equal(result, expected)

            # specify columns
            expected = DataFrame(comb, columns=names[::-1])
            result = DataFrame(mrecs, columns=names[::-1])
            assert_fr_equal(result, expected)

            # specify index
            expected = DataFrame(comb, columns=names, index=[1, 2])
            result = DataFrame(mrecs, index=[1, 2])
            assert_fr_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:44,代码来源:test_constructors.py

示例11: test_constructor_mrecarray

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def test_constructor_mrecarray(self):
        # Ensure mrecarray produces frame identical to dict of masked arrays
        # from GH3479

        assert_fr_equal = functools.partial(tm.assert_frame_equal,
                                            check_index_type=True,
                                            check_column_type=True,
                                            check_frame_type=True)
        arrays = [
            ('float', np.array([1.5, 2.0])),
            ('int', np.array([1, 2])),
            ('str', np.array(['abc', 'def'])),
        ]
        for name, arr in arrays[:]:
            arrays.append(('masked1_' + name,
                           np.ma.masked_array(arr, mask=[False, True])))
        arrays.append(('masked_all', np.ma.masked_all((2,))))
        arrays.append(('masked_none',
                       np.ma.masked_array([1.0, 2.5], mask=False)))

        # call assert_frame_equal for all selections of 3 arrays
        for comb in itertools.combinations(arrays, 3):
            names, data = zip(*comb)
            mrecs = mrecords.fromarrays(data, names=names)

            # fill the comb
            comb = dict([(k, v.filled()) if hasattr(
                v, 'filled') else (k, v) for k, v in comb])

            expected = DataFrame(comb, columns=names)
            result = DataFrame(mrecs)
            assert_fr_equal(result, expected)

            # specify columns
            expected = DataFrame(comb, columns=names[::-1])
            result = DataFrame(mrecs, columns=names[::-1])
            assert_fr_equal(result, expected)

            # specify index
            expected = DataFrame(comb, columns=names, index=[1, 2])
            result = DataFrame(mrecs, index=[1, 2])
            assert_fr_equal(result, expected) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:44,代码来源:test_constructors.py

示例12: __init__

# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import masked_all [as 别名]
def __init__(self, nwalkers, ndim, lnpostfn, transd=False,
                 processes=None, pool=None, args=[]):
        self.nwalkers = nwalkers
        self.dim = ndim
        self._kde = None
        self._kde_size = self.nwalkers
        self._updates = []
        self._burnin_length = None

        self._get_lnpost = lnpostfn
        self._lnpost_args = args

        self.iterations = 0
        self.stored_iterations = 0

        self.processes = processes

        self._managing_pool = False
        if pool is not None:
            self.pool = pool

        elif self.processes == 1:
            self.pool = SerialPool()

        else:
            self._managing_pool = True

            # create a multiprocessing pool
            self.pool = Pool(self.processes)

        if not hasattr(self.pool, 'map'):
            raise AttributeError("Pool object must have a map() method.")

        self._transd = transd
        if self._transd:
            self._chain = ma.masked_all((0, self.nwalkers, self.dim))
        else:
            self._chain = np.zeros((0, self.nwalkers, self.dim))

        self._lnpost = np.empty((0, self.nwalkers))
        self._lnprop = np.empty((0, self.nwalkers))
        self._acceptance = np.zeros((0, self.nwalkers))
        self._blobs = []

        self._last_run_mcmc_result = None
        self._burnin_spaces = None
        self._failed_p = None 
开发者ID:bfarr,项目名称:kombine,代码行数:49,代码来源:sampler.py


注:本文中的numpy.ma.masked_all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。