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

Python numpy.trunc函数代码示例

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

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



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


示例16: base_link_coords_lethal

 def base_link_coords_lethal(self, origin, yaw, x, y,):
     x_rot = x*np.cos(yaw) - y*np.sin(yaw)        
     y_rot = y*np.cos(yaw) + x*np.sin(yaw)        
     x_index = np.trunc(origin[1] + x_rot/self.costmap_info.resolution).astype('i2')
     y_index = np.trunc(origin[0] + y_rot/self.costmap_info.resolution).astype('i2')
     if ( x_index < self.costmap_info.height and
          y_index < self.costmap_info.height and  
          x_index >= 0 and
          y_index >= 0 ):
         return self.costmap[y_index, x_index] > self._lethal_threshold
     else:
         rospy.logwarn("SEARCH_AREA_CHECK off costmap! Returning True.")
         return True
开发者ID:contradict,项目名称:SampleReturn,代码行数:13,代码来源:vfh_move_server.py


示例17: jd2gregorian

def jd2gregorian(jd):
    t1900 = (jd - 2415019.5)/365.25
    year = 1900 + np.trunc(t1900)
    leap_years = np.trunc((year - 1900 - 1)*0.25)
    days = (jd - 2415019.5) - ((year - 1900)*365.0 + leap_years)
    
    if days < 1.0:
        year = year - 1
        leap_years = np.trunc((year - 1900 - 1)*0.25)
        days = (jd - 2415019.5) - ((year - 1900)*365.0 + leap_years)
        
    (month, day, hours, minutes, seconds) = days2ymdhms(days, year)
    return (year, month, day, hours, minutes, seconds)
开发者ID:xagriff,项目名称:vallado,代码行数:13,代码来源:astro_time.py


示例18: _update_fields

 def _update_fields(self):
     from numpy import trunc
     
     # map mouse location to array index
     frotmp = int(trunc(self.custtool.yval))
     totmp = int(trunc(self.custtool.xval))
     
     # check if within range
     sh = self.data[self.data_name].shape
     # assume matrix whose shape is (# of rows, # of columns)
     if frotmp >= 0 and frotmp < sh[0] and totmp >= 0 and totmp < sh[1]:
         self.fro = frotmp
         self.to = totmp
         self.val = self.data[self.data_name][self.fro, self.to]
开发者ID:neurodebian,项目名称:connectomeviewer,代码行数:14,代码来源:matrix_viewer_old.py


示例19: _update_fields

 def _update_fields(self):
     from numpy import trunc
     
     # map mouse location to array index
     frotmp = int(trunc(self.custtool.yval))
     totmp = int(trunc(self.custtool.xval))
     
     # check if within range
     sh = self.matrix_data_ref[self.edge_parameter_name].shape
     # assume matrix whose shape is (# of rows, # of columns)
     if frotmp >= 0 and frotmp < sh[0] and totmp >= 0 and totmp < sh[1]:
         self.fro = self.labels[frotmp]
         self.to = self.labels[totmp]
         self.val = self.matrix_data_ref[self.edge_parameter_name][frotmp, totmp]
开发者ID:151706061,项目名称:connectomeviewer,代码行数:14,代码来源:cmatrix_viewer.py


示例20: interpolate_at_equidistant_time_steps

 def interpolate_at_equidistant_time_steps(self):
     #determine min and max of time series
     min_t=numpy.min(self.ta)/RESAMPLE_TIME_STEP
     max_t=numpy.max(self.ta)/RESAMPLE_TIME_STEP
     # mapping to quantization steps RESAMPLE_TIME_STEP
     min_ti=numpy.trunc(min_t)*RESAMPLE_TIME_STEP
     max_ti=numpy.trunc(max_t)*RESAMPLE_TIME_STEP
     number_of_samples=numpy.rint((max_ti-min_ti)/RESAMPLE_TIME_STEP+1+EPSILON)
     #print number_of_samples
     self.edta=numpy.linspace(min_ti, max_ti, number_of_samples)
     #print self.edta
     #scipy.interpolate.splrep: Find the B-spline representation of 1-D curve.
     rep = scipy.interpolate.splrep(self.ta,self.ca, k=1)
     self.edca=interpolate.splev(self.edta,rep)
开发者ID:FUEL4EP,项目名称:consumption_analysis,代码行数:14,代码来源:consal.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numpy.uint函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.true_divide函数代码示例发布时间: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