• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.bool_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_numpy_scalar_bool

 def test_numpy_scalar_bool(self):
     x = np.bool_(True)
     x_rec = self.encode_decode(x)
     assert x == x_rec and type(x) == type(x_rec)
     x = np.bool_(False)
     x_rec = self.encode_decode(x)
     assert x == x_rec and type(x) == type(x_rec)
开发者ID:cjermain,项目名称:msgpack-numpy,代码行数:7,代码来源:msgpack_numpy.py


示例2: __init__

 def __init__(self, x, y):
             
     assert np.ndim(x)==2 and np.ndim(y)==2 and np.shape(x)==np.shape(y), \
         'x and y must be 2D arrays of the same size.'
     
     if np.any(np.isnan(x)) or np.any(np.isnan(y)):
         x = np.ma.masked_where( (isnan(x)) | (isnan(y)) , x)
         y = np.ma.masked_where( (isnan(x)) | (isnan(y)) , y)
         
     self.x_vert = x
     self.y_vert = y
     
     mask_shape = tuple([n-1 for n in self.x_vert.shape])
     self.mask_rho = np.ones(mask_shape, dtype='d')
     
     # If maskedarray is given for verticies, modify the mask such that 
     # non-existant grid points are masked.  A cell requires all four
     # verticies to be defined as a water point.
     if isinstance(self.x_vert, np.ma.MaskedArray):
         mask = (self.x_vert.mask[:-1,:-1] | self.x_vert.mask[1:,:-1] | \
                 self.x_vert.mask[:-1,1:] | self.x_vert.mask[1:,1:])
         self.mask_rho = np.asarray(~(~np.bool_(self.mask_rho) | mask), dtype='d')
     
     if isinstance(self.y_vert, np.ma.MaskedArray):
         mask = (self.y_vert.mask[:-1,:-1] | self.y_vert.mask[1:,:-1] | \
                 self.y_vert.mask[:-1,1:] | self.y_vert.mask[1:,1:])
         self.mask_rho = np.asarray(~(~np.bool_(self.mask_rho) | mask), dtype='d')
     
     self._calculate_subgrids()
     self._calculate_metrics()        
开发者ID:jingzhiyou,项目名称:octant,代码行数:30,代码来源:grid.py


示例3: test_numpy

    def test_numpy(self):
        assert chash(np.bool_(True)) == chash(np.bool_(True))

        assert chash(np.int8(1)) == chash(np.int8(1))
        assert chash(np.int16(1))
        assert chash(np.int32(1))
        assert chash(np.int64(1))

        assert chash(np.uint8(1))
        assert chash(np.uint16(1))
        assert chash(np.uint32(1))
        assert chash(np.uint64(1))

        assert chash(np.float32(1)) == chash(np.float32(1))
        assert chash(np.float64(1)) == chash(np.float64(1))
        assert chash(np.float128(1)) == chash(np.float128(1))

        assert chash(np.complex64(1+1j)) == chash(np.complex64(1+1j))
        assert chash(np.complex128(1+1j)) == chash(np.complex128(1+1j))
        assert chash(np.complex256(1+1j)) == chash(np.complex256(1+1j))

        assert chash(np.datetime64('2000-01-01')) == chash(np.datetime64('2000-01-01'))
        assert chash(np.timedelta64(1,'W')) == chash(np.timedelta64(1,'W'))

        self.assertRaises(ValueError, chash, np.object())

        assert chash(np.array([[1, 2], [3, 4]])) == \
            chash(np.array([[1, 2], [3, 4]]))
        assert chash(np.array([[1, 2], [3, 4]])) != \
            chash(np.array([[1, 2], [3, 4]]).T)
        assert chash(np.array([1, 2, 3])) == chash(np.array([1, 2, 3]))
        assert chash(np.array([1, 2, 3], dtype=np.int32)) != \
            chash(np.array([1, 2, 3], dtype=np.int64))
开发者ID:lebedov,项目名称:chash,代码行数:33,代码来源:test_chash.py


示例4: mask_rho

    def mask_rho(self):
        """
        Returns the mask for the cells
        """
        if self._mask_rho is None:
            mask_shape = tuple([n - 1 for n in self.x_vert.shape])
            self._mask_rho = numpy.ones(mask_shape, dtype='d')

            # If maskedarray is given for vertices, modify the mask such that
            # non-existant grid points are masked.  A cell requires all four
            # verticies to be defined as a water point.
            if isinstance(self.x_vert, numpy.ma.MaskedArray):
                mask = (self.x_vert.mask[:-1, :-1] | self.x_vert.mask[1:, :-1] |
                        self.x_vert.mask[:-1, 1:] | self.x_vert.mask[1:, 1:])
                self._mask_rho = numpy.asarray(
                    ~(~numpy.bool_(self.mask_rho) | mask),
                    dtype='d'
                )

            if isinstance(self.y_vert, numpy.ma.MaskedArray):
                mask = (self.y_vert.mask[:-1, :-1] | self.y_vert.mask[1:, :-1] |
                        self.y_vert.mask[:-1, 1:] | self.y_vert.mask[1:, 1:])
                self._mask_rho = numpy.asarray(
                    ~(~numpy.bool_(self.mask_rho) | mask),
                    dtype='d'
                )

        return self._mask_rho
开发者ID:phobson,项目名称:pygridgen,代码行数:28,代码来源:grid.py


示例5: test00b_setBoolAttributes

    def test00b_setBoolAttributes(self):
        """Checking setting Bool attributes (scalar, NumPy case)"""

        self.array.attrs.pq = numpy.bool_(True)
        self.array.attrs.qr = numpy.bool_(False)
        self.array.attrs.rs = numpy.bool_(True)

        # Check the results
        if common.verbose:
            print "pq -->", self.array.attrs.pq
            print "qr -->", self.array.attrs.qr
            print "rs -->", self.array.attrs.rs

        if self.close:
            if common.verbose:
                print "(closing file version)"
            self.fileh.close()
            self.fileh = openFile(self.file, mode = "r+")
            self.root = self.fileh.root
            self.array = self.fileh.root.anarray

        assert isinstance(self.root.anarray.attrs.pq, numpy.bool_)
        assert isinstance(self.root.anarray.attrs.qr, numpy.bool_)
        assert isinstance(self.root.anarray.attrs.rs, numpy.bool_)
        assert self.root.anarray.attrs.pq == True
        assert self.root.anarray.attrs.qr == False
        assert self.root.anarray.attrs.rs == True
开发者ID:rlim19,项目名称:DumpScripts,代码行数:27,代码来源:test_attributes.py


示例6: test_numpy_scalar_conversion_values

 def test_numpy_scalar_conversion_values(self):
     self.assertEqual(nd.as_py(nd.array(np.bool_(True))), True)
     self.assertEqual(nd.as_py(nd.array(np.bool_(False))), False)
     self.assertEqual(nd.as_py(nd.array(np.int8(100))), 100)
     self.assertEqual(nd.as_py(nd.array(np.int8(-100))), -100)
     self.assertEqual(nd.as_py(nd.array(np.int16(20000))), 20000)
     self.assertEqual(nd.as_py(nd.array(np.int16(-20000))), -20000)
     self.assertEqual(nd.as_py(nd.array(np.int32(1000000000))), 1000000000)
     self.assertEqual(nd.as_py(nd.array(np.int64(-1000000000000))),
                      -1000000000000)
     self.assertEqual(nd.as_py(nd.array(np.int64(1000000000000))),
                      1000000000000)
     self.assertEqual(nd.as_py(nd.array(np.int32(-1000000000))),
                      -1000000000)
     self.assertEqual(nd.as_py(nd.array(np.uint8(200))), 200)
     self.assertEqual(nd.as_py(nd.array(np.uint16(50000))), 50000)
     self.assertEqual(nd.as_py(nd.array(np.uint32(3000000000))), 3000000000)
     self.assertEqual(nd.as_py(nd.array(np.uint64(10000000000000000000))),
                      10000000000000000000)
     self.assertEqual(nd.as_py(nd.array(np.float32(2.5))), 2.5)
     self.assertEqual(nd.as_py(nd.array(np.float64(2.5))), 2.5)
     self.assertEqual(nd.as_py(nd.array(np.complex64(2.5-1j))), 2.5-1j)
     self.assertEqual(nd.as_py(nd.array(np.complex128(2.5-1j))), 2.5-1j)
     if np.__version__ >= '1.7':
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13'))),
                          date(2000, 12, 13))
开发者ID:garaud,项目名称:dynd-python,代码行数:26,代码来源:test_numpy_interop.py


示例7: test_scalar_bool

    def test_scalar_bool(self):
        x = np.bool_(1)
        x_rec = self.encode_decode(x)
        tm.assert_almost_equal(x, x_rec)

        x = np.bool_(0)
        x_rec = self.encode_decode(x)
        tm.assert_almost_equal(x, x_rec)
开发者ID:chrish42,项目名称:pandas,代码行数:8,代码来源:test_packers.py


示例8: test_normalize_json

def test_normalize_json():
    doc = {"foo": {numpy.bool_(True): "value"},
           "what": numpy.bool_(False),
           "this": numpy.PINF}
    normalized_doc = normalize_json(doc)
    assert isinstance(normalized_doc['what'], bool)
    assert isinstance(list(normalized_doc['foo'].keys())[0], bool)
    assert normalized_doc['this'] == "Infinity"
开发者ID:wiki-ai,项目名称:revscoring,代码行数:8,代码来源:test_util.py


示例9: eval

    def eval(self, row, dataset):
        result = np.bool_(self.value[0].eval(row, dataset))

        for oper, val in self.operator_operands(self.value[1:]):
            val = np.bool_(val.eval(row, dataset))
            result = self.operation(oper, result, val)

        return result
开发者ID:sparkplug,项目名称:bamboo,代码行数:8,代码来源:operations.py


示例10: test_numpy_scalar_bool

 def test_numpy_scalar_bool(self):
     x = np.bool_(True)
     x_rec = self.encode_decode(x)
     assert_equal(x, x_rec)
     assert_equal(type(x), type(x_rec))
     x = np.bool_(False)
     x_rec = self.encode_decode(x)
     assert_equal(x, x_rec)
     assert_equal(type(x), type(x_rec))
开发者ID:lebedov,项目名称:msgpack-numpy,代码行数:9,代码来源:tests.py


示例11: get_results

    def get_results(self, conditions):
        
        
        self.conditions = dict(zip(conditions, range(len(conditions))))
        
        # Loads data for each subject
        # results is in the form (condition x subjects x runs x matrix)
        results = load_matrices(self.path, conditions)
        
        # Check if there are NaNs in the data
        nan_mask = np.isnan(results)
        for _ in range(len(results.shape) - 2):
            # For each condition/subject/run check if we have nan
            nan_mask = nan_mask.sum(axis=0)
        
        
            
        
        #pl.imshow(np.bool_(nan_mask), interpolation='nearest')
        #print np.nonzero(np.bool_(nan_mask)[0,:])
        # Clean NaNs
        results = results[:,:,:,~np.bool_(nan_mask)]
        
        # Reshaping because numpy masking flattens matrices        
        rows = np.sqrt(results.shape[-1])
        shape = list(results.shape[:-1])
        shape.append(int(rows))
        shape.append(-1)
        results = results.reshape(shape)
        
        # We apply z fisher to results
        zresults = z_fisher(results)
        zresults[np.isinf(zresults)] = 1
        
        self.results = zresults
        
        # Select mask to delete labels
        roi_mask = ~np.bool_(np.diagonal(nan_mask))

        # Get some information to store stuff
        self.store_details(roi_mask)   

        # Mean across runs
        zmean = zresults.mean(axis=2)
                
        new_shape = list(zmean.shape[-2:])
        new_shape.insert(0, -1)
        
        zreshaped = zmean.reshape(new_shape)
        
        upper_mask = np.ones_like(zreshaped[0])
        upper_mask[np.tril_indices(zreshaped[0].shape[0])] = 0
        upper_mask = np.bool_(upper_mask)
        
        # Returns the mask of the not available ROIs.
        self.nan_mask = nan_mask
        return self.nan_mask
开发者ID:robbisg,项目名称:mvpa_itab_wu,代码行数:57,代码来源:connectivity.py


示例12: test_index_bool

    def test_index_bool( self ):
        a = np.arange(5)

        x = np.bool_(False)
        y = np.bool_(True)

        z = a[x:y]

        assert_equal( z, [0] )
开发者ID:258073127,项目名称:MissionPlanner,代码行数:9,代码来源:test_scalartypes.py


示例13: test_dmat_add

 def test_dmat_add(self):
     assert_equals(self.pos_vec + self.neg_vec, self.unknown_vec)
     result = Sign(np.bool_(True), self.arr)
     assert_equals(self.pos_vec + Sign.NEGATIVE, result)
     assert_equals(self.neg_vec + self.zero_vec, self.neg_vec)
     result = Sign(np.bool_(True), ~self.true_mat)
     assert_equals(self.neg_mat + Sign.NEGATIVE, result)
     assert_equals(self.pos_vec + self.pos_vec, self.pos_vec)
     assert_equals(self.unknown_mat + self.zero_mat, self.unknown_mat)
     assert_equals(Sign.UNKNOWN + self.pos_mat, Sign.UNKNOWN)
开发者ID:BvanP,项目名称:cvxpy,代码行数:10,代码来源:test_sign.py


示例14: test_mask_ratio

 def test_mask_ratio(self):
     self.assertEqual(mask_ratio(True), 1)
     self.assertEqual(mask_ratio(np.bool_(True)), 1)
     self.assertEqual(mask_ratio(False), 0)
     self.assertEqual(mask_ratio(np.bool_(False)), 0)
     array = np.ma.array(range(10))
     self.assertEqual(mask_ratio(np.ma.getmaskarray(array)), 0)
     array[0] = np.ma.masked
     self.assertEqual(mask_ratio(np.ma.getmaskarray(array)), 0.1)
     invalid_array = np.ma.array(range(100), mask=[True]*100)
     self.assertEqual(mask_ratio(np.ma.getmaskarray(invalid_array)), 1)
开发者ID:azraelrabbit,项目名称:FlightDataUtilities,代码行数:11,代码来源:array_operations_test.py


示例15: test_astype

 def test_astype(self):
     import numpy as np
     a = np.bool_(True).astype(np.float32)
     assert type(a) is np.float32
     assert a == 1.0
     a = np.bool_(True).astype('int32')
     assert type(a) is np.int32
     assert a == 1
     a = np.str_('123').astype('int32')
     assert type(a) is np.int32
     assert a == 123
开发者ID:abhinavthomas,项目名称:pypy,代码行数:11,代码来源:test_scalar.py


示例16: test_local_time_constraint_utc

def test_local_time_constraint_utc():
    time = Time('2001-02-03 04:05:06')
    subaru = Observer.at_site("Subaru")
    constraint = LocalTimeConstraint(min=dt.time(23, 50), max=dt.time(4, 8))
    is_constraint_met = constraint(subaru, None, times=time)
    assert is_constraint_met is np.bool_(True)

    constraint = LocalTimeConstraint(min=dt.time(0, 2), max=dt.time(4, 3))
    is_constraint_met = constraint(subaru, None, times=time)
    assert is_constraint_met is np.bool_(False)

    constraint = LocalTimeConstraint(min=dt.time(3, 8), max=dt.time(5, 35))
    is_constraint_met = constraint(subaru, None, times=time)
    assert is_constraint_met is np.bool_(True)
开发者ID:bmorris3,项目名称:astroplan,代码行数:14,代码来源:test_constraints.py


示例17: construct_4d_adjacency_list

def construct_4d_adjacency_list(mask, numx=1, numy=1, numz=1, numt=1, nt=0):
    """
    Basically the prepare_adj function from regreg, but with less options.
    """
    
    regions = np.zeros(mask.shape)
    regions.shape = mask.shape
    reg_values = np.unique(regions)
    
    vmap = np.cumsum(mask).reshape(mask.shape)
    mask = np.bool_(mask.copy())
    vmap[~mask] = -1
    vmap -= 1 # sets vmap's values from 0 to mask.sum()-1
    
    adj = []
    nx, ny, nz = mask.shape
    
    for i, j, k, t in itertools.product(range(nx), range(ny),
                                        range(nz), range(nt)):
        
        if mask[i, j, k, t]:
            
            local_map = vmap[max((i-numx), 0):(i+numx+1),
                             max((j-numy), 0):(j+numy+1),
                             max((k-numz), 0):(k+numz+1),
                             max((t-numt), 0):(t+numt+1)]
            
            local_reg = regions[max((i-numx), 0):(i+numx+1),
                                max((j-numy), 0):(j+numy+1),
                                max((k-numz), 0):(k+numz+1),
                                max((t-numt), 0):(t+numt+1)]
            
            region = regions[i, j, k, t]
            ind = (local_map > -1) * (local_reg == region)
            ind = np.bool_(ind)
            nbrs = np.array(local_map[ind], dtype=np.int)
            adj.append(nbrs)
            
    
    for i, a in enumerate(adj):
        a[np.equal(a, i)] = -1
        
    num_ind = np.max([len(a) for a in adj])
    adjarray = -np.ones((len(adj), num_ind), dtype=np.int)
    
    for i in range(len(adj)):
        for j in range(len(adj[i])):
            adjarray[i,j] = adj[i][j]
            
    return adjarray
开发者ID:kieferkat,项目名称:kk-tools,代码行数:50,代码来源:adjacency.py


示例18: __init__

 def __init__(self, log_parameters=[], **kwargs):
     # Runs Individual.__init__ for default object initialization.
     super(Plankton, self).__init__(**kwargs)
     # Some parameters and initializations
     self.state_parameters = ['t', 'x', 'y', 'z', 'P', 'N_P']
     # ... history list
     self._attributes['history'] = dict()
     # ... log list
     n = self.size()
     extra = {key: [nan] * n for key in log_parameters}
     # Start history log
     self.append_history(extra=extra)
     # Assumes every individual is inside the model domain
     self.in_domain = bool_(self.x) | bool_(self.y)
开发者ID:regeirk,项目名称:gaia,代码行数:14,代码来源:individuals.py


示例19: test_numpy_scalar_conversion_values

 def test_numpy_scalar_conversion_values(self):
     self.assertEqual(nd.as_py(nd.array(np.bool_(True))), True)
     self.assertEqual(nd.as_py(nd.array(np.bool_(False))), False)
     self.assertEqual(nd.as_py(nd.array(np.int8(100))), 100)
     self.assertEqual(nd.as_py(nd.array(np.int8(-100))), -100)
     self.assertEqual(nd.as_py(nd.array(np.int16(20000))), 20000)
     self.assertEqual(nd.as_py(nd.array(np.int16(-20000))), -20000)
     self.assertEqual(nd.as_py(nd.array(np.int32(1000000000))), 1000000000)
     self.assertEqual(nd.as_py(nd.array(np.int64(-1000000000000))),
                      -1000000000000)
     self.assertEqual(nd.as_py(nd.array(np.int64(1000000000000))),
                      1000000000000)
     self.assertEqual(nd.as_py(nd.array(np.int32(-1000000000))),
                      -1000000000)
     self.assertEqual(nd.as_py(nd.array(np.uint8(200))), 200)
     self.assertEqual(nd.as_py(nd.array(np.uint16(50000))), 50000)
     self.assertEqual(nd.as_py(nd.array(np.uint32(3000000000))), 3000000000)
     self.assertEqual(nd.as_py(nd.array(np.uint64(10000000000000000000))),
                      10000000000000000000)
     self.assertEqual(nd.as_py(nd.array(np.float32(2.5))), 2.5)
     self.assertEqual(nd.as_py(nd.array(np.float64(2.5))), 2.5)
     self.assertEqual(nd.as_py(nd.array(np.complex64(2.5-1j))), 2.5-1j)
     self.assertEqual(nd.as_py(nd.array(np.complex128(2.5-1j))), 2.5-1j)
     if np.__version__ >= '1.7':
         # Various date units
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000'))),
                          date(2000, 1, 1))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12'))),
                          date(2000, 12, 1))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13'))),
                          date(2000, 12, 13))
         # Various datetime units
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12Z'))),
                          datetime(2000, 12, 13, 12, 0))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12:30Z'))),
                          datetime(2000, 12, 13, 12, 30))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('1823-12-13T12:30Z'))),
                          datetime(1823, 12, 13, 12, 30))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12:30:24Z'))),
                          datetime(2000, 12, 13, 12, 30, 24))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12:30:24.123Z'))),
                          datetime(2000, 12, 13, 12, 30, 24, 123000))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12:30:24.123456Z'))),
                          datetime(2000, 12, 13, 12, 30, 24, 123456))
         self.assertEqual(nd.as_py(nd.array(np.datetime64('2000-12-13T12:30:24.123456124Z'))),
                          datetime(2000, 12, 13, 12, 30, 24, 123456))
         self.assertEqual(str(nd.array(np.datetime64('2000-12-13T12:30:24.123456124Z'))),
                          '2000-12-13T12:30:24.1234561Z')
         self.assertEqual(str(nd.array(np.datetime64('1842-12-13T12:30:24.123456124Z'))),
                          '1842-12-13T12:30:24.1234561Z')
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:50,代码来源:test_numpy_interop.py


示例20: __init__

 def __init__(self, endog, exog, censors):
     self.nobs = float(np.shape(exog)[0])
     self.endog = endog.reshape(self.nobs, 1)
     self.exog = exog.reshape(self.nobs, -1)
     self.censors = censors.reshape(self.nobs, 1)
     self.nvar = self.exog.shape[1]
     idx = np.lexsort((-self.censors[:, 0], self.endog[:, 0]))
     self.endog = self.endog[idx]
     self.exog = self.exog[idx]
     self.censors = self.censors[idx]
     self.censors[-1] = 1  # Sort in init, not in function
     self.uncens_nobs = np.sum(self.censors)
     self.uncens_endog = self.endog[np.bool_(self.censors), :].\
       reshape(-1, 1)
     self.uncens_exog = self.exog[np.bool_(self.censors.flatten()), :]
开发者ID:dengemann,项目名称:statsmodels,代码行数:15,代码来源:aft_el.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.broadcast函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.bool8函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap