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


Python numpy.bitwise_not方法代码示例

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


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

示例1: test_values

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def test_values(self):
        for dt in self.bitwise_types:
            zeros = np.array([0], dtype=dt)
            ones = np.array([-1], dtype=dt)
            msg = "dt = '%s'" % dt.char

            assert_equal(np.bitwise_not(zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_not(ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_or(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_or(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_or(ones, ones), ones, err_msg=msg)

            assert_equal(np.bitwise_xor(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_xor(zeros, ones), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, zeros), ones, err_msg=msg)
            assert_equal(np.bitwise_xor(ones, ones), zeros, err_msg=msg)

            assert_equal(np.bitwise_and(zeros, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(zeros, ones), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, zeros), zeros, err_msg=msg)
            assert_equal(np.bitwise_and(ones, ones), ones, err_msg=msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_umath.py

示例2: testBitwiseOp

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def testBitwiseOp(self, onp_op, lnp_op, rng_factory, shapes, dtypes):
    rng = rng_factory()
    args_maker = self._GetArgsMaker(rng, shapes, dtypes)
    has_python_scalar = jtu.PYTHON_SCALAR_SHAPE in shapes
    self._CheckAgainstNumpy(onp_op, lnp_op, args_maker, check_dtypes=True)
    if onp_op == onp.bitwise_not and has_python_scalar:
      # For bitwise_not with a Python `int`, npe.jit may choose a different
      # dtype for the `int` from onp's choice, which may result in a different
      # result value, so we skip _CompileAndCheck.
      return
    # Numpy does value-dependent dtype promotion on Python/numpy/array scalars
    # which `jit` can't do (when np.result_type is called inside `jit`, tensor
    # values are not available), so we skip dtype check in this case.
    check_dtypes = not(set(shapes) & set([jtu.NUMPY_SCALAR_SHAPE,
                                          jtu.PYTHON_SCALAR_SHAPE, ()]))
    self._CompileAndCheck(lnp_op, args_maker, check_dtypes=check_dtypes) 
开发者ID:google,项目名称:trax,代码行数:18,代码来源:lax_numpy_test.py

示例3: simulate_conditional

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def simulate_conditional(self, X):
    """ Draws random samples from the conditional distribution

    Args:
      X: x to be conditioned on when drawing a sample from y ~ p(y|x) - numpy array of shape (n_samples, ndim_x)

    Returns:
      Conditional random samples y drawn from p(y|x) - numpy array of shape (n_samples, ndim_y)
    """
    mean = self.arma_c * (1 - self.arma_a1) + self.arma_a1 * X
    y_ar = self.random_state.normal(loc=mean, scale=self.std, size=X.shape[0])

    mean_jump = mean + self.jump_mean
    y_jump = self.random_state.normal(loc=mean_jump, scale=self.jump_std, size=X.shape[0])

    jump_bernoulli = self.random_state.uniform(size=X.shape[0]) < self.jump_prob

    return X, np.select([jump_bernoulli, np.bitwise_not(jump_bernoulli)], [y_jump, y_ar]) 
开发者ID:freelunchtheorem,项目名称:Conditional_Density_Estimation,代码行数:20,代码来源:ArmaJump.py

示例4: _numpy

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def _numpy(self, data, weights, shape):
        q = self.quantity(data)
        self._checkNPQuantity(q, shape)
        self._checkNPWeights(weights, shape)
        weights = self._makeNPWeights(weights, shape)

        # no possibility of exception from here on out (for rollback)
        self.entries += float(weights.sum())

        import numpy
        selection = numpy.isnan(q)
        numpy.bitwise_not(selection, selection)
        numpy.bitwise_and(selection, weights > 0.0, selection)
        q = q[selection]
        weights = weights[selection]
        q *= weights

        self.sum += float(q.sum()) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:20,代码来源:sum.py

示例5: _numpy

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def _numpy(self, data, weights, shape):
        q = self.quantity(data)
        self._checkNPQuantity(q, shape)
        self._checkNPWeights(weights, shape)
        weights = self._makeNPWeights(weights, shape)

        # no possibility of exception from here on out (for rollback)
        import numpy
        selection = numpy.isnan(q)
        numpy.bitwise_not(selection, selection)
        numpy.bitwise_and(selection, weights > 0.0, selection)
        q = q[selection]

        self.entries += float(weights.sum())

        if math.isnan(self.min):
            if q.shape[0] > 0:
                self.min = float(q.min())
        else:
            if q.shape[0] > 0:
                self.min = min(self.min, float(q.min())) 
开发者ID:histogrammar,项目名称:histogrammar-python,代码行数:23,代码来源:minmax.py

示例6: transform

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def transform(iterable: Iterable, inplace: bool = True, columns: List[str] = None, transform_fn: Callable[[Iterable], Iterable] = None):
    if inplace is True:
        transformed_iterable = iterable
    else:
        transformed_iterable = iterable.copy()

    if isinstance(transformed_iterable, pd.DataFrame):
        is_list = False
    else:
        is_list = True
        transformed_iterable = pd.DataFrame(transformed_iterable, columns=columns)

    transformed_iterable.fillna(0, inplace=True)

    if transform_fn is None:
        raise NotImplementedError()

    if columns is None:
        columns = transformed_iterable.columns

    for column in columns:
        transformed_iterable[column] = transform_fn(transformed_iterable[column])

    transformed_iterable.fillna(method="bfill", inplace=True)
    transformed_iterable[np.bitwise_not(np.isfinite(transformed_iterable))] = 0

    if is_list:
        transformed_iterable = transformed_iterable.values

    return transformed_iterable 
开发者ID:notadamking,项目名称:RLTrader,代码行数:32,代码来源:transform.py

示例7: _next_observation

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def _next_observation(self):
        self.current_ohlcv = self.data_provider.next_ohlcv()
        self.timestamps.append(pd.to_datetime(self.current_ohlcv.Date.item(), unit='s'))
        self.observations = self.observations.append(self.current_ohlcv, ignore_index=True)

        if self.stationarize_obs:
            observations = log_and_difference(self.observations, inplace=False)
        else:
            observations = self.observations

        if self.normalize_obs:
            observations = max_min_normalize(observations)

        obs = observations.values[-1]

        if self.stationarize_obs:
            scaled_history = log_and_difference(self.account_history, inplace=False)
        else:
            scaled_history = self.account_history

        if self.normalize_obs:
            scaled_history = max_min_normalize(scaled_history, inplace=False)

        obs = np.insert(obs, len(obs), scaled_history.values[-1], axis=0)

        obs = np.reshape(obs.astype('float16'), self.obs_shape)
        obs[np.bitwise_not(np.isfinite(obs))] = 0

        return obs 
开发者ID:notadamking,项目名称:RLTrader,代码行数:31,代码来源:TradingEnv.py

示例8: test_types

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def test_types(self):
        for dt in self.bitwise_types:
            zeros = np.array([0], dtype=dt)
            ones = np.array([-1], dtype=dt)
            msg = "dt = '%s'" % dt.char

            assert_(np.bitwise_not(zeros).dtype == dt, msg)
            assert_(np.bitwise_or(zeros, zeros).dtype == dt, msg)
            assert_(np.bitwise_xor(zeros, zeros).dtype == dt, msg)
            assert_(np.bitwise_and(zeros, zeros).dtype == dt, msg) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_umath.py

示例9: bitwise_not

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def bitwise_not(x):
  def f(x):
    if x.dtype == tf.bool:
      return tf.logical_not(x)
    return tf.bitwise.invert(x)
  return _scalar(f, x) 
开发者ID:google,项目名称:trax,代码行数:8,代码来源:math_ops.py

示例10: saturation

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def saturation(im: np.ndarray) -> np.ndarray:
    """
    Saturation as from Binghamton toolbox
    :param im: type np.uint8
    :return: saturation map from input im
    """
    assert (im.dtype == np.uint8)

    if im.ndim == 2:
        im.shape += (1,)

    h, w, ch = im.shape

    if im.max() < 250:
        return np.ones((h, w, ch))

    im_h = im - np.roll(im, (0, 1), (0, 1))
    im_v = im - np.roll(im, (1, 0), (0, 1))
    satur_map = \
        np.bitwise_not(
            np.bitwise_and(
                np.bitwise_and(
                    np.bitwise_and(
                        im_h != 0, im_v != 0
                    ), np.roll(im_h, (0, -1), (0, 1)) != 0
                ), np.roll(im_v, (-1, 0), (0, 1)) != 0
            )
        )

    max_ch = im.max(axis=0).max(axis=0)

    for ch_idx, max_c in enumerate(max_ch):
        if max_c > 250:
            satur_map[:, :, ch_idx] = \
                np.bitwise_not(
                    np.bitwise_and(
                        im[:, :, ch_idx] == max_c, satur_map[:, :, ch_idx]
                    )
                )

    return satur_map 
开发者ID:polimi-ispl,项目名称:prnu-python,代码行数:43,代码来源:functions.py

示例11: local_maxima

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def local_maxima(arr):
    # http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array/3689710#3689710
    """
    Takes an array and detects the troughs using the local maximum filter.
    Returns a boolean mask of the troughs (i.e. 1 when
    the pixel's value is the neighborhood maximum, 0 otherwise)
    """
    # define an connected neighborhood
    # http://www.scipy.org/doc/api_docs/SciPy.ndimage.morphology.html#generate_binary_structure
    neighborhood = morphology.generate_binary_structure(len(arr.shape),2)
    # apply the local maximum filter; all locations of maximal value 
    # in their neighborhood are set to 1
    # http://www.scipy.org/doc/api_docs/SciPy.ndimage.filters.html#maximum_filter
    local_max = (filters.maximum_filter(arr, footprint=neighborhood)==arr)
    # local_max is a mask that contains the peaks we are 
    # looking for, but also the background.
    # In order to isolate the peaks we must remove the background from the mask.
    # 
    # we create the mask of the background
    background = (arr==arr.min())           # mxu: in the original version, was         background = (arr==0)
    # 
    # a little technicality: we must erode the background in order to 
    # successfully subtract it from local_max, otherwise a line will 
    # appear along the background border (artifact of the local maximum filter)
    # http://www.scipy.org/doc/api_docs/SciPy.ndimage.morphology.html#binary_erosion
    eroded_background = morphology.binary_erosion(
        background, structure=neighborhood, border_value=1)
    # 
    # we obtain the final mask, containing only peaks, 
    # by removing the background from the local_max mask
    #detected_maxima = local_max - eroded_backround             # mxu: this is the old version, but the boolean minus operator is deprecated
    detected_maxima = np.bitwise_and(local_max, np.bitwise_not(eroded_background))          # Material nonimplication, see http://en.wikipedia.org/wiki/Material_nonimplication
    return np.where(detected_maxima) 
开发者ID:xulabs,项目名称:aitom,代码行数:35,代码来源:local_extrema.py

示例12: mask_table

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def mask_table(region, table, negate=False, racol='ra', deccol='dec'):
    """
    Apply a given mask (region) to the table, removing all the rows with ra/dec inside the region
    If negate=False then remove the rows with ra/dec outside the region.


    Parameters
    ----------
    region : :class:`AegeanTools.regions.Region`
        Region to mask.

    table : Astropy.table.Table
        Table to be masked.

    negate :  bool
        If True then pixels *outside* the region are masked.
        Default = False.

    racol, deccol : str
        The name of the columns in `table` that should be interpreted as ra and dec.
        Default = 'ra', 'dec'

    Returns
    -------
    masked : Astropy.table.Table
        A view of the given table which has been masked.
    """
    inside = region.sky_within(table[racol], table[deccol], degin=True)
    if not negate:
        mask = np.bitwise_not(inside)
    else:
        mask = inside
    return table[mask] 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:35,代码来源:MIMAS.py

示例13: sky_within

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def sky_within(self, ra, dec, degin=False):
        """
        Test whether a sky position is within this region

        Parameters
        ----------
        ra, dec : float
            Sky position.

        degin : bool
            If True the ra/dec is interpreted as degrees, otherwise as radians.
            Default = False.

        Returns
        -------
        within : bool
            True if the given position is within one of the region's pixels.
        """
        sky = self.radec2sky(ra, dec)

        if degin:
            sky = np.radians(sky)

        theta_phi = self.sky2ang(sky)
        # Set values that are nan to be zero and record a mask
        mask = np.bitwise_not(np.logical_and.reduce(np.isfinite(theta_phi), axis=1))
        theta_phi[mask, :] = 0

        theta, phi = theta_phi.transpose()
        pix = hp.ang2pix(2**self.maxdepth, theta, phi, nest=True)
        pixelset = self.get_demoted()
        result = np.in1d(pix, list(pixelset))
        # apply the mask and set the shonky values to False
        result[mask] = False
        return result 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:37,代码来源:regions.py

示例14: test_success

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import bitwise_not [as 别名]
def test_success():
    mask_collection_0 = binary_mask_collection_2d()
    binary_arrays, physical_ticks = binary_arrays_2d()
    binary_arrays_negated = [
        np.bitwise_not(binary_array)
        for binary_array in binary_arrays
    ]
    mask_collection_1 = BinaryMaskCollection.from_binary_arrays_and_ticks(
        binary_arrays_negated, None, physical_ticks, None)

    merged = SimpleMerge().run([mask_collection_0, mask_collection_1])

    assert _ticks_equal(merged._pixel_ticks, mask_collection_0._pixel_ticks)
    assert _ticks_equal(merged._physical_ticks, mask_collection_0._physical_ticks)
    assert len(mask_collection_0) + len(mask_collection_1) == len(merged)

    # go through all the original uncroppped masks, and verify that they are somewhere in the merged
    # set.
    for mask_collection in (mask_collection_0, mask_collection_1):
        for ix in range(len(mask_collection)):
            uncropped_original_mask = mask_collection.uncropped_mask(ix)
            for jx in range(len(merged)):
                uncropped_copy_mask = merged.uncropped_mask(jx)

                if uncropped_original_mask.equals(uncropped_copy_mask):
                    # found the copy, break
                    break
            else:
                pytest.fail("could not find mask in merged set.") 
开发者ID:spacetx,项目名称:starfish,代码行数:31,代码来源:test_simple.py


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