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


Python numpy.trunc函数代码示例

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


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

示例1: sort_by_cells

    def sort_by_cells(self):
        zp, yp, xp = self.zp, self.yp, self.xp
        vz, vy, vx = self.vz, self.vy, self.vx
        Lz, Ly, Lx = self.Lz, self.Ly, self.Lx
        cell       = self.cell
        cell_span  = self.cell_span
        N_cells    = self.N_cells

        Cz = Lz/N_cells
        Cy = Ly/N_cells
        Cx = Lx/N_cells

        zp_cell = np.trunc(zp/Cz)
        yp_cell = np.trunc(yp/Cy)
        xp_cell = np.trunc(xp/Cx)

        cell[:] = xp_cell+yp_cell*N_cells+zp_cell*N_cells**2

        s = cell.argsort()
        zp[:] = zp[s]
        yp[:] = yp[s]
        xp[:] = xp[s]
        vz[:] = vz[s]
        vy[:] = vy[s]
        vx[:] = vx[s]
        cell[:] = cell[s]
        cell_span[:-1] = np.searchsorted(cell, self.cell_vals)
        cell_span[-1]  = self.N
开发者ID:dreamer2368,项目名称:py3d3v,代码行数:28,代码来源:pic3d3v.py

示例2: morph

def morph(face1, face1pts, face2, face2pts, warp_frac=0.5, dissolve_frac=0.5):
    #we assume face1pts and face2pts contains the corners of the image
    face1 = np.copy(face1)
    face2 = np.copy(face2)
    avgpts = (1-warp_frac)*face1pts + warp_frac*face2pts
    avgpts[:4] = np.trunc(avgpts[:4])
    face = np.zeros((avgpts[3,0], avgpts[3,1], 3))
    delaunay_triangulation = Delaunay(avgpts)
    simplices = delaunay_triangulation.simplices
    triang1 = [[face1pts[s[0]], face1pts[s[1]], face1pts[s[2]]] for s in simplices]
    triang2 = [[face2pts[s[0]], face2pts[s[1]], face2pts[s[2]]] for s in simplices]
    triang = [[avgpts[s[0]], avgpts[s[1]], avgpts[s[2]]] for s in simplices]
    affine_t1 = [compute_transform(triang[i], triang1[i]) for i in range(len(triang1))]
    affine_t2 = [compute_transform(triang[i], triang2[i]) for i in range(len(triang2))]
    for y in range(face.shape[0]):
        for x in range(face.shape[1]):
            trinum1 = tsearch((y, x), triang1)
            vec1 = np.dot(affine_t1[trinum1], np.array([x, y, 1]))
            vec1 = np.trunc(vec1)
            trinum2 = tsearch((y, x), triang2)
            vec2 = np.dot(affine_t2[trinum2], np.array([x, y, 1]))
            vec2 = np.trunc(vec2)
            try:
                face[y,x,:] = (1-dissolve_frac)*face1[vec1[1]-1,vec1[0]-1] + dissolve_frac*face2[vec2[1]-1,vec2[0]-1]
            except:
                print (vec1[1]-1,vec1[0]-1), (vec2[1]-1,vec2[0]-1)
    return face
开发者ID:vinyin,项目名称:facemorph,代码行数:27,代码来源:main.py

示例3: init_boid

    def init_boid(amaze):
        pos = np.zeros(cfg.Dimensions, dtype=np.float32)
        # Start from a random cell
        pos[0] = np.float32(np.trunc(np.random.uniform(0, cfg.maze_width)))
        pos[1] = np.float32(np.trunc(np.random.uniform(0, cfg.maze_height)))

        # Ensure that we are not placing the boid into a wall ---------------------
        # Change position until hit a free cell
        while isinstance(
                amaze.matrix[int(pos[0])][int(pos[1])].shape,
                maze.Wall):
            # While the cell is filled with a wall (==1)
            pos[0] = np.float32(np.trunc(np.random.uniform(0, cfg.maze_width)))
            pos[1] = np.float32(np.trunc(np.random.uniform(0, cfg.maze_height)))
            # Check that we are not placing the boind into the wall

        # Move boid to the center of the cell
        pos[0] += 0.5
        pos[1] += 0.5
        vel = np.zeros(cfg.Dimensions, dtype=np.float32)

        # TODO: change pheromone_level type to uint16
        pheromone_level = np.zeros([1], dtype=np.float32)

        return np.concatenate((pos, vel, pheromone_level))
开发者ID:naummo,项目名称:swarm_maze_opencl_solver,代码行数:25,代码来源:agents.py

示例4: set_jds

    def set_jds(self, val1, val2):
        self._check_scale(self._scale)  # Validate scale.

        sum12, err12 = two_sum(val1, val2)
        iy_start = np.trunc(sum12).astype(np.int)
        extra, y_frac = two_sum(sum12, -iy_start)
        y_frac += extra + err12

        val = (val1 + val2).astype(np.double)
        iy_start = np.trunc(val).astype(np.int)

        imon = np.ones_like(iy_start)
        iday = np.ones_like(iy_start)
        ihr = np.zeros_like(iy_start)
        imin = np.zeros_like(iy_start)
        isec = np.zeros_like(y_frac)

        # Possible enhancement: use np.unique to only compute start, stop
        # for unique values of iy_start.
        scale = self.scale.upper().encode('ascii')
        jd1_start, jd2_start = erfa.dtf2d(scale, iy_start, imon, iday,
                                          ihr, imin, isec)
        jd1_end, jd2_end = erfa.dtf2d(scale, iy_start + 1, imon, iday,
                                      ihr, imin, isec)

        t_start = Time(jd1_start, jd2_start, scale=self.scale, format='jd')
        t_end = Time(jd1_end, jd2_end, scale=self.scale, format='jd')
        t_frac = t_start + (t_end - t_start) * y_frac

        self.jd1, self.jd2 = day_frac(t_frac.jd1, t_frac.jd2)
开发者ID:BTY2684,项目名称:astropy,代码行数:30,代码来源:formats.py

示例5: split_data

def split_data(dataset):
    '''
    Split the dataset into training, validation, and test set. The split will be 70, 20, 10
    :param dataset: the entire dataset containing positive and negative images. each row is a tuple containing the data and label
    :param pixel_res: the number of neurons per image
    :return: a tuple of training, validation, and test
    '''

    # shuffle the data to randomize
    shuffled = np.random.permutation(dataset)

    # get the sizes based on split percentage for each set
    print 'total dataset size:', len(shuffled)
    ts = np.trunc(len(shuffled) * 0.64) # train
    print ts
    vs = np.trunc(len(shuffled) * 0.16)# valid
    print vs
    tts = np.trunc(len(shuffled) * 0.20 )# test
    print tts

    train_input, train_label = get_input_label(shuffled[:ts])
    valid_input, valid_label = get_input_label(shuffled[ts:ts+vs])
    test_input, test_label = get_input_label(shuffled[ts+vs:])

    return train_input, train_label, valid_input, valid_label, test_input, test_label
开发者ID:lemquan,项目名称:master_thesis,代码行数:25,代码来源:load_data.py

示例6: time2hms

def time2hms(time_in_seconds):
    temp = time_in_seconds/3600.0
    hours = np.trunc(temp)
    minutes = np.trunc((temp - hours)*60)
    seconds = (temp - hours - minutes/60)*3600
    
    return (hours, minutes, seconds)
开发者ID:xagriff,项目名称:vallado,代码行数:7,代码来源:astro_time.py

示例7: lim_precision_inputs

def lim_precision_inputs(inputs, bits, precision):
        lim_inputs = np.empty(inputs.shape)
        for index, value in np.ndenumerate(inputs):
                        if value>=0:
                                lim_inputs[index] = np.trunc((value * (1 << precision)) % (1 << bits) + 0.5)# * (1.0 / (1 << precision))
                        else:
                                lim_inputs[index] = -np.trunc((-value * (1 << precision)) % (1 << bits) + 0.5)# * (1.0 / (1 << precision))
        return lim_inputs.astype(theano.config.floatX)
开发者ID:Thalnos,项目名称:8bit-deep-learning,代码行数:8,代码来源:cifarmctest.py

示例8: plot

    def plot(self, database, dsid):
        """Plot positions of all counterparts for all (unique) sources for
        the given dataset.

        The positions of all (unique) sources in the running catalog are
        at the centre, whereas the positions of all their associated
        sources are scattered around the central point.  Axes are in
        arcsec relative to the running catalog position.
        """

        query = """\
SELECT x.id
      ,x.ra
      ,x.decl
      ,3600 * (x.ra - r.wm_ra) as ra_dist_arcsec
      ,3600 * (x.decl - r.wm_decl) as decl_dist_arcsec
      ,x.ra_err/2
      ,x.decl_err/2
      ,r.wm_ra_err/2
      ,r.wm_decl_err/2
  FROM assocxtrsource a
      ,extractedsource x
      ,runningcatalog r
      ,image im1
 WHERE a.runcat = r.id
   AND a.xtrsrc = x.id
   AND x.image = im1.id
   AND im1.dataset = %s

"""
        results = zip(*database.db.get(query, dsid))

        if not results:
            return None
        xtrsrc_id = results[0]
        ra = results[1]
        decl = results[2]
        ra_dist_arcsec = results[3]
        decl_dist_arcsec = results[4]
        ra_err = results[5]
        decl_err = results[6]
        wm_ra_err = results[7]
        wm_decl_err = results[8]

        axes = self.figure.add_subplot(1, 1, 1)
        axes.errorbar(ra_dist_arcsec, decl_dist_arcsec, xerr=ra_err, yerr=decl_err,
                      fmt='+', color='b', label="xtr")
        axes.set_xlabel(r'RA (arcsec)')
        axes.set_ylabel(r'DEC (arcsec)')
        lim = 1 + max(int(numpy.trunc(max(abs(min(ra_dist_arcsec)),
                                          abs(max(ra_dist_arcsec))))),
                      int(numpy.trunc(max(abs(min(decl_dist_arcsec)),
                                          abs(max(decl_dist_arcsec))))))
        axes.set_xlim(xmin= -lim, xmax=lim)
        axes.set_ylim(ymin= -lim, ymax=lim)
        axes.grid(False)
        # Shifts plot spacing to ensure that axes labels are displayed
        self.figure.tight_layout()
开发者ID:bartscheers,项目名称:TKP-web,代码行数:58,代码来源:quality.py

示例9: gather

def gather(data,lc):
    i = numpy.trunc(lc[0])
    j = numpy.trunc(lc[1])
    di = lc[0] - i
    dj = lc[1] - j
    return  (data[i][j]*(1-di)*(1-dj) +
          data[i+1][j]*(di)*(1-dj) + 
          data[i][j+1]*(1-di)*(dj) + 
          data[i+1][j+1]*(di)*(dj)) 
开发者ID:StanczakDominik,项目名称:PICCBlog,代码行数:9,代码来源:rz-pic1.py

示例10: bprop_input

 def bprop_input (self, input, output):
     sx = None
     if self.thresh != 0:
         sx = input.x / self.thresh
         np.trunc(sx, sx)
         np.sign(sx, sx)
     else:
         sx = np.sign(input.x)
     input.dx += sx * output.dx
开发者ID:ysulsky,项目名称:eblearn-python,代码行数:9,代码来源:transfer.py

示例11: trunc

def trunc(x):
    """
    Truncate the values to the integer value without rounding
    """
    if isinstance(x, UncertainFunction):
        mcpts = np.trunc(x._mcpts)
        return UncertainFunction(mcpts)
    else:
        return np.trunc(x)
开发者ID:mkouhia,项目名称:mcerp,代码行数:9,代码来源:umath.py

示例12: julian_date

def julian_date(yr, mo, d, hr, minute, sec, leap_sec=False):
    x = (7*(yr + np.trunc((mo + 9)/12)))/4.0
    y = (275*mo)/9.0
    if leap_sec:
        t = 61.0
    else:
        t = 60.0
    z = (sec/t + minute)/60.0 + hr
    jd = 367*yr - np.trunc(x) + np.trunc(y) + d + 1721013.5 + z/24.0
    return jd
开发者ID:xagriff,项目名称:vallado,代码行数:10,代码来源:astro_time.py

示例13: scatter

def scatter(data,lc,value):
    i = numpy.trunc(lc[0])
    j = numpy.trunc(lc[1])
    di = lc[0] - i
    dj = lc[1] - j
            
    data[i][j] += (1-di)*(1-dj)*value
    data[i+1][j] += (di)*(1-dj)*value
    data[i][j+1] += (1-di)*(dj)*value
    data[i+1][j+1] += (di)*(dj)*value
开发者ID:StanczakDominik,项目名称:PICCBlog,代码行数:10,代码来源:rz-pic1.py

示例14: truncate

 def truncate(self, h, m, s):
     d = np.trunc(s / self.slim)
     s = s % self.slim
     m += d
     d = np.trunc(m / self.mlim)
     m = m % self.mlim
     h += d
     d = np.trunc(h / self.hlim)
     h = h % self.hlim
     return [int(h), int(m), float(s)]
开发者ID:kharyuk,项目名称:astro,代码行数:10,代码来源:coord.py

示例15: tens_nort

def tens_nort(drnms, labels,
               mza = 100.,
               mzb = 1000.,
               mz_step = 1e-0, # 0.01
               blcleaned = True):

    ulist = []
    llist = []
    elist = []

    for drnm in drnms:
        if blcleaned:
            fnm = drnm + '_blcleaned.npz'
        else:
            fnm = drnm + '.npz'
        f = np.load("./" + drnm + '/' + fnm)

        negsp = f['negsp']
        negmz = f['negmz']

        possp = f['possp']
        posmz = f['posmz']

        label = f['label']

        for k in xrange(negsp.shape[1]): # must be equal to pos_s.shape[1] // number of samples

            if label[k] not in labels:
                continue
            llist.append(label[k])
            elist.append(drnm)

            # u is 2D array: (m/z, polarity) = (m/z, 2), but polarity is fixednow
            
            u = np.zeros( ( (mzb - mza) / mz_step, 2))

            for i in xrange(negsp.shape[0]):
                if negsp[i, k] != 0:
                    if (negmz[i] < mza) or (negmz[i] >= mzb):
                        continue
                    mzind = np.trunc((negmz[i] - mza)/ mz_step)
                    mzind = int(mzind)
                    #if u[mzind, rtind, 0] != 0:
                    u[mzind, 0] = max(u[mzind, 0], negsp[i, k]) # to deal with crossing values
            for i in xrange(possp.shape[0]):
                if possp[i, k] != 0:
                    if (posmz[i] < mza) or (posmz[i] >= mzb):
                        continue
                    mzind = np.trunc((posmz[i] - mza)/ mz_step)
                    mzind = int(mzind)
                    #if u[mzind, rtind, 0] != 0:
                    u[mzind, 1] = max(u[mzind, 1], possp[i, k]) # to deal with crossing values
            ulist.append(u)
    u = np.array(ulist)
    return u, llist, elist
开发者ID:dmitro-nazarenko,项目名称:chemfin-open,代码行数:55,代码来源:tensorize.py


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