當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.divmod方法代碼示例

本文整理匯總了Python中numpy.divmod方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.divmod方法的具體用法?Python numpy.divmod怎麽用?Python numpy.divmod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.divmod方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_vmat

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def get_vmat(mf, mfset, disp):
    '''
    computing <u|dVxc/dR|v>
    '''
    vmat=[]
    mygrad = mf.nuc_grad_method()
    ve = mygrad.get_veff() + mygrad.get_hcore() + mf.mol.intor("int1e_ipkin")
    RESTRICTED = (ve.ndim==3)
    aoslice = mf.mol.aoslice_by_atom()
    for ki, (mf1, mf2) in enumerate(mfset):
        atmid, axis = np.divmod(ki, 3)
        p0, p1 = aoslice[atmid][2:]
        vfull1 = mf1.get_veff() + mf1.get_hcore() - mf1.mol.intor_symmetric('int1e_kin')  # <u+|V+|v+>
        vfull2 = mf2.get_veff() + mf2.get_hcore() - mf2.mol.intor_symmetric('int1e_kin')  # <u-|V-|v->
        vfull = (vfull1 - vfull2)/disp  # (<p+|V+|q+>-<p-|V-|q->)/dR
        if RESTRICTED:
            vfull[p0:p1] -= ve[axis,p0:p1]
            vfull[:,p0:p1] -= ve[axis,p0:p1].T
        else:
            vfull[:,p0:p1] -= ve[:,axis,p0:p1]
            vfull[:,:,p0:p1] -= ve[:,axis,p0:p1].transpose(0,2,1)
        vmat.append(vfull)

    return np.asarray(vmat) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:26,代碼來源:eph_fd.py

示例2: enforce_pbc

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def enforce_pbc(lattvecs, epos):
    """Enforces periodic boundary conditions on a set of configs.
    Args:

      lattvecs: orthogonal lattice vectors defining 3D torus: (3,3)

      init_epos: attempted new electron coordinates: (nconfig,3)

    Returns:
    
      final_epos: final electron coordinates with PBCs imposed: (nconfig,3)

      wraparound: vector used to bring a given electron back to the simulation cell written in terms of lattvecs: (nconfig,3)
    """
    # Writes epos in terms of (lattice vecs) fractional coordinates
    recpvecs = np.linalg.inv(lattvecs)
    epos_lvecs_coord = np.dot(epos, recpvecs)

    # Finds position inside box and wraparound vectors (in lattice vector coordinates)
    tmp = np.divmod(epos_lvecs_coord, 1)
    wraparound = tmp[0]
    final_epos = np.dot(tmp[1], lattvecs)

    return final_epos, wraparound 
開發者ID:WagnerGroup,項目名稱:pyqmc,代碼行數:26,代碼來源:pbc.py

示例3: test_float_remainder_exact

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def test_float_remainder_exact(self):
        # test that float results are exact for small integers. This also
        # holds for the same integers scaled by powers of two.
        nlst = list(range(-127, 0))
        plst = list(range(1, 128))
        dividend = nlst + [0] + plst
        divisor = nlst + plst
        arg = list(itertools.product(dividend, divisor))
        tgt = list(divmod(*t) for t in arg)

        a, b = np.array(arg, dtype=int).T
        # convert exact integer results from Python to float so that
        # signed zero can be used, it is checked.
        tgtdiv, tgtrem = np.array(tgt, dtype=float).T
        tgtdiv = np.where((tgtdiv == 0.0) & ((b < 0) ^ (a < 0)), -0.0, tgtdiv)
        tgtrem = np.where((tgtrem == 0.0) & (b < 0), -0.0, tgtrem)

        for op in [floor_divide_and_remainder, np.divmod]:
            for dt in np.typecodes['Float']:
                msg = 'op: %s, dtype: %s' % (op.__name__, dt)
                fa = a.astype(dt)
                fb = b.astype(dt)
                div, rem = op(fa, fb)
                assert_equal(div, tgtdiv, err_msg=msg)
                assert_equal(rem, tgtrem, err_msg=msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:test_umath.py

示例4: test_float_remainder_roundoff

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def test_float_remainder_roundoff(self):
        # gh-6127
        dt = np.typecodes['Float']
        for op in [floor_divide_and_remainder, np.divmod]:
            for dt1, dt2 in itertools.product(dt, dt):
                for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):
                    fmt = 'op: %s, dt1: %s, dt2: %s, sg1: %s, sg2: %s'
                    msg = fmt % (op.__name__, dt1, dt2, sg1, sg2)
                    a = np.array(sg1*78*6e-8, dtype=dt1)
                    b = np.array(sg2*6e-8, dtype=dt2)
                    div, rem = op(a, b)
                    # Equal assertion should hold when fmod is used
                    assert_equal(div*b + rem, a, err_msg=msg)
                    if sg2 == -1:
                        assert_(b < rem <= 0, msg)
                    else:
                        assert_(b > rem >= 0, msg) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_umath.py

示例5: node_label

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def node_label(subgraph):
    # an implementation of the proposed double-radius node labeling (DRNL)
    K = subgraph.shape[0]
    subgraph_wo0 = subgraph[1:, 1:]
    subgraph_wo1 = subgraph[[0]+range(2, K), :][:, [0]+range(2, K)]
    dist_to_0 = ssp.csgraph.shortest_path(subgraph_wo0, directed=False, unweighted=True)
    dist_to_0 = dist_to_0[1:, 0]
    dist_to_1 = ssp.csgraph.shortest_path(subgraph_wo1, directed=False, unweighted=True)
    dist_to_1 = dist_to_1[1:, 0]
    d = (dist_to_0 + dist_to_1).astype(int)
    d_over_2, d_mod_2 = np.divmod(d, 2)
    labels = 1 + np.minimum(dist_to_0, dist_to_1).astype(int) + d_over_2 * (d_over_2 + d_mod_2 - 1)
    labels = np.concatenate((np.array([1, 1]), labels))
    labels[np.isinf(labels)] = 0
    labels[labels>1e6] = 0  # set inf labels to 0
    labels[labels<-1e6] = 0  # set -inf labels to 0
    
    return labels 
開發者ID:xchadesi,項目名稱:GPF,代碼行數:20,代碼來源:subgraphs.py

示例6: test_get_diag

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def test_get_diag(dtype, num_charges, Ds, flow):
  np.random.seed(10)
  np_flow = -np.int((np.int(flow) - 0.5) * 2)
  indices = [
      Index(
          BaseCharge(
              np.random.randint(-2, 3, (num_charges, Ds[n])),
              charge_types=[U1Charge] * num_charges), flow) for n in range(2)
  ]
  arr = BlockSparseTensor.random(indices, dtype=dtype)
  fused = fuse_charges(arr.flat_charges, arr.flat_flows)
  inds = np.nonzero(fused == np.zeros((num_charges, 1), dtype=np.int16))[0]
  # pylint: disable=no-member
  left, _ = np.divmod(inds, Ds[1])
  unique = np.unique(
      np_flow * (indices[0]._charges[0].charges[:, left]), axis=1)
  diagonal = diag(arr)
  sparse_blocks, _, block_shapes = _find_diagonal_sparse_blocks(
      arr.flat_charges, arr.flat_flows, 1)
  data = np.concatenate([
      np.diag(np.reshape(arr.data[sparse_blocks[n]], block_shapes[:, n]))
      for n in range(len(sparse_blocks))
  ])
  np.testing.assert_allclose(data, diagonal.data)
  np.testing.assert_allclose(unique, diagonal.flat_charges[0].unique_charges) 
開發者ID:google,項目名稱:TensorNetwork,代碼行數:27,代碼來源:linalg_test.py

示例7: halton

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def halton(dimensions: int, size: int, start: int, scramble: bool, state: np.random.RandomState) -> Tuple[Array, Array]:
    """Generate nodes and weights for integration according to the Halton sequence."""

    # generate Halton sequences
    sequences = np.zeros((size, dimensions))
    for dimension in range(dimensions):
        base = get_prime(dimension)
        factor = 1 / base
        indices = np.arange(start, start + size)
        while 1 - factor < 1:
            indices, remainders = np.divmod(indices, base)
            if scramble:
                remainders = state.permutation(base)[remainders]
            sequences[:, dimension] += factor * remainders
            factor /= base

    # transform the sequences and construct weights
    nodes = scipy.stats.norm().ppf(sequences)
    weights = np.repeat(1 / size, size)
    return nodes, weights 
開發者ID:jeffgortmaker,項目名稱:pyblp,代碼行數:22,代碼來源:integration.py

示例8: o2a

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def o2a(self, io, unique=False):
        """ Atomic index corresponding to the orbital indicies.

        This is a particurlaly slow algorithm due to for-loops.

        Note that this will preserve the super-cell offsets.

        Parameters
        ----------
        io : array_like
             List of indices to return the atoms for
        unique : bool, optional
             If True only return the unique atoms.
        """
        if isinstance(io, Integral):
            if unique:
                return np.unique(np.argmax(io % self.no <= self.lasto) + (io // self.no) * self.na)
            return np.argmax(io % self.no <= self.lasto) + (io // self.no) * self.na

        isc, io = np.divmod(_a.asarrayi(io).ravel(), self.no)
        a = list_index_le(io, self.lasto)
        if unique:
            return np.unique(a + isc * self.na)
        return a + isc * self.na 
開發者ID:zerothi,項目名稱:sisl,代碼行數:26,代碼來源:geometry.py

示例9: test_two_argument_two_output_ufunc_inplace

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def test_two_argument_two_output_ufunc_inplace(self, value):
        v = value * u.m
        divisor = 70.*u.cm
        v1 = v.copy()
        tmp = v.copy()
        check = np.divmod(v1, divisor, out=(tmp, v1))
        assert check[0] is tmp and check[1] is v1
        assert tmp.unit == u.dimensionless_unscaled
        assert v1.unit == v.unit
        v2 = v.copy()
        check2 = np.divmod(v2, divisor, out=(v2, tmp))
        assert check2[0] is v2 and check2[1] is tmp
        assert v2.unit == u.dimensionless_unscaled
        assert tmp.unit == v.unit
        v3a = v.copy()
        v3b = v.copy()
        check3 = np.divmod(v3a, divisor, out=(v3a, v3b))
        assert check3[0] is v3a and check3[1] is v3b
        assert v3a.unit == u.dimensionless_unscaled
        assert v3b.unit == v.unit 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:22,代碼來源:test_quantity_ufuncs.py

示例10: get_vmat

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import divmod [as 別名]
def get_vmat(mf, mfset, disp):
    nconfigs = len(mfset)
    vmat=[]
    mygrad = mf.nuc_grad_method()
    veff  = mygrad.get_veff()
    RESTRICTED = (veff.ndim==4)
    v1e = mygrad.get_hcore() - np.asarray(mf.cell.pbc_intor("int1e_ipkin", kpts=mf.kpts))
    if RESTRICTED:
        vtmp = veff - v1e.transpose(1,0,2,3)
    else:
        vtmp = veff - v1e.transpose(1,0,2,3)[:,None]

    aoslice = mf.cell.aoslice_by_atom()
    for i in range(nconfigs):
        atmid, axis = np.divmod(i, 3)
        p0, p1 = aoslice[atmid][2:]
        mf1, mf2 = mfset[i]
        vfull1 = mf1.get_veff() + mf1.get_hcore() - mf1.cell.pbc_intor('int1e_kin', kpts=mf1.kpts)  # <u+|V+|v+>
        vfull2 = mf2.get_veff() + mf2.get_hcore() - mf2.cell.pbc_intor('int1e_kin', kpts=mf2.kpts)  # <u-|V-|v->
        vfull = (vfull1 - vfull2)/disp  # (<p+|V+|q+>-<p-|V-|q->)/dR
        if RESTRICTED:
            vfull[:,p0:p1] -= vtmp[axis,:,p0:p1]
            vfull[:,:,p0:p1] -= vtmp[axis,:,p0:p1].transpose(0,2,1).conj()
        else:
            vfull[:,:,p0:p1] -= vtmp[axis,:,:,p0:p1]
            vfull[:,:,:,p0:p1] -= vtmp[axis,:,:,p0:p1].transpose(0,1,3,2).conj()

        vmat.append(vfull)

    vmat= np.asarray(vmat)
    if RESTRICTED:
        return vmat[:,0]
    else:
        return vmat[:,:,0] 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:36,代碼來源:eph_fd.py


注:本文中的numpy.divmod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。