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


Python numpy.flipud函数代码示例

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


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

示例1: produce_heatmap

def produce_heatmap(model, every = True, save = False):
    col_label = range(28)
    row_label = range(28)
    if every:
        for i in range(10):
            plt.pcolor(np.flipud(model[i]))
            plt.xticks(col_label)
            plt.yticks(row_label)
            plt.axis('off')
            plt.title("HeatMap for %d" % (i))
            cb = plt.colorbar()
            cb.set_label("Frequency")
            if save:
                plt.savefig('imgs/%d.png' % (i), bbox_inches='tight')
            else:
                plt.show()
            plt.close()
    else:
        plt.pcolor(np.flipud(model))
        plt.xticks(col_label)
        plt.yticks(row_label)
        plt.axis('off')
        cb = plt.colorbar()
        cb.set_label("Frequency")
        if save:
            plt.savefig('imgs/temp.png', bbox_inches='tight')
        else:
            plt.show()
        plt.close()
开发者ID:hhuang97,项目名称:HandReader2,代码行数:29,代码来源:main.py

示例2: get_output

    def get_output(self, idx):
        img_id=idx/self.pertnum
        pert_id=idx%self.pertnum
        rot_id=pert_id%self.param['rotate']
        off_id=pert_id/self.param['rotate']
        [h, w]=self.output[img_id].shape
        [dy, dx]=self.get_offset(h, w, off_id)
        dy+=self.param['mrgsize']
        dx+=self.param['mrgsize']
        res=self.output[img_id][dy:dy+self.param['outsize'], dx:dx+self.param['outsize']]
        #res=np.rot90(res) #rotate 90
        if rot_id==1:
            res=np.fliplr(res)
        elif rot_id==2:
            res=np.flipud(res).T
        elif rot_id==3:
            res=res.T
        elif rot_id==4:
            res=np.fliplr(res).T
        elif rot_id==5:
            res=np.flipud(res)
        elif rot_id==6:
            res=np.rot90(res,2)
        elif rot_id==7:
            res=np.rot90(res,2).T

        return res
开发者ID:lelegan,项目名称:DLSR,代码行数:27,代码来源:ListaPrvd_regr.py

示例3: rotate_data

def rotate_data(bg, overlay, slices_list, axis_name, shape):
    # Rotate the data as required
    # Return the rotated data, and an updated slice list if necessary
    if axis_name == 'axial':
        # Align so that right is right
        overlay = np.rot90(overlay)
        overlay = np.fliplr(overlay)
        bg = np.rot90(bg)
        bg = np.fliplr(bg)
    
    elif axis_name == 'coronal':
        overlay = np.rot90(overlay)
        bg = np.rot90(bg)
        overlay = np.flipud(np.swapaxes(overlay, 0, 2))
        bg = np.flipud(np.swapaxes(bg, 0, 2))
        slices_list[1] = [ shape - n - 3 for n in slices_list[1] ] 
        
    elif axis_name == 'sagittal':
        overlay = np.flipud(np.swapaxes(overlay, 0, 2))
        bg = np.flipud(np.swapaxes(bg, 0, 2))
    
    else:
        print '\n************************'
        print 'ERROR: data could not be rotated\n'
        parser.print_help()
        sys.exit()
    
    return bg, overlay, slices_list
开发者ID:KirstieJane,项目名称:DESCRIBING_DATA,代码行数:28,代码来源:MakePngs_DTI.py

示例4: get_image_quadrants

def get_image_quadrants(IM, reorient=False):
    """
    Given an image (m,n) return its 4 quadrants Q0, Q1, Q2, Q3
    as defined in abel.hansenlaw.iabel_hansenlaw

    Parameters:
      - IM: 1D or 2D array
      - reorient: reorient image as required by abel.hansenlaw.iabel_hansenlaw
    """
    IM = np.atleast_2d(IM)

    n, m = IM.shape

    n_c = n//2 + n%2
    m_c = m//2 + m%2

    # define 4 quadrants of the image
    # see definition in abel.hansenlaw.iabel_hansenlaw
    Q1 = IM[:n_c, :m_c]
    Q2 = IM[-n_c:, :m_c]
    Q0 = IM[:n_c, -m_c:]
    Q3 = IM[-n_c:, -m_c:]

    if reorient:
        Q1 = np.fliplr(Q1)
        Q3 = np.flipud(Q3)
        Q2 = np.fliplr(np.flipud(Q2))

    return Q0, Q1, Q2, Q3
开发者ID:stggh,项目名称:PyAbel,代码行数:29,代码来源:symmetry.py

示例5: generateWedge

def generateWedge(a, b, n, type, plotShape=False):
    # Define x and y coordinate
    xFrontTop_ = np.linspace(0, a / 2.0, n);                    xFrontTop = xFrontTop_
    xBackTop_ = np.linspace(a / 2.0, a, n);                     xBackTop = xBackTop_[1:]
    xBackBottom_ = np.flipud(np.linspace(a / 2.0, a, n));       xBackBottom = xBackBottom_[1:]
    xFrontBottom_ = np.flipud(np.linspace(0, a / 2.0, n));      xFrontBottom = xFrontBottom_[1:-1]

    yFrontTop_ = b / a * xFrontTop_;                            yFrontTop = yFrontTop_
    yBackTop_ = -b / a * (xBackTop_ - a / 2.0) + b / 2;         yBackTop = yBackTop_[1:]
    yBackBottom_ = b / a * (xBackBottom_ - a / 2.0) - b / 2;    yBackBottom = yBackBottom_[1:]
    yFrontBottom_ = -b / a * xFrontBottom_;                     yFrontBottom = yFrontBottom_[1:-1]

    if type == 'twoSided':
        # x = np.concatenate((xFrontTop, xBackTop, xBackBottom, xFrontBottom))
        # y = np.concatenate((yFrontTop, yBackTop, yBackBottom, yFrontBottom))
        xTop = np.concatenate((xFrontTop, xBackTop))
        xBottom = np.concatenate((xBackBottom, xFrontBottom))
        yTop = np.concatenate((yFrontTop, yBackTop))
        yBottom = np.concatenate((yBackBottom, yFrontBottom))
    elif type == 'oneSided':
        x = np.concatenate((xFrontTop, xBackTop))
        y = np.concatenate((yFrontTop, yBackTop))

    if plotShape:
        plt.figure()
        plt.plot(x, y, 'k')
        plt.xlim([-5, 14])
        plt.ylim([-5, 5])
        plt.show()

    return (x, y)
开发者ID:kooroshg1,项目名称:Piston_Theory,代码行数:31,代码来源:pistonSolver.py

示例6: update_lambda

    def update_lambda(self, sstats, word_list, opt_o):
        self.m_status_up_to_date = False
        # rhot will be between 0 and 1, and says how much to weight
        # the information we got from this mini-chunk.
        rhot = self.m_scale * pow(self.m_tau + self.m_updatect, -self.m_kappa)
        if rhot < rhot_bound:
            rhot = rhot_bound
        self.m_rhot = rhot

        # Update appropriate columns of lambda based on documents.
        self.m_lambda[:, word_list] = self.m_lambda[:, word_list] * (1 - rhot) + \
            rhot * self.m_D * sstats.m_var_beta_ss / sstats.m_chunksize
        self.m_lambda_sum = (1 - rhot) * self.m_lambda_sum + \
            rhot * self.m_D * np.sum(sstats.m_var_beta_ss, axis=1) / sstats.m_chunksize

        self.m_updatect += 1
        self.m_timestamp[word_list] = self.m_updatect
        self.m_r.append(self.m_r[-1] + np.log(1 - rhot))

        self.m_varphi_ss = (1.0 - rhot) * self.m_varphi_ss + rhot * \
            sstats.m_var_sticks_ss * self.m_D / sstats.m_chunksize

        if opt_o:
            self.optimal_ordering()

        ## update top level sticks
        self.m_var_sticks[0] = self.m_varphi_ss[:self.m_T - 1] + 1.0
        var_phi_sum = np.flipud(self.m_varphi_ss[1:])
        self.m_var_sticks[1] = np.flipud(np.cumsum(var_phi_sum)) + self.m_gamma
开发者ID:Autodidact24,项目名称:gensim,代码行数:29,代码来源:hdpmodel.py

示例7: setUp

 def setUp(self):
     """
     This generates a minimum data-set to be used for the regression.
     """
     # Test A: Generates a data set assuming b=1 and N(m=4.0)=10.0 events
     self.dmag = 0.1
     mext = np.arange(4.0, 7.01, 0.1)
     self.mval = mext[0:-1] + self.dmag / 2.0
     self.bval = 1.0
     self.numobs = np.flipud(
         np.diff(np.flipud(10.0 ** (-self.bval * mext + 8.0))))
     # Test B: Generate a completely artificial catalogue using the
     # Gutenberg-Richter distribution defined above
     numobs = np.around(self.numobs)
     size = int(np.sum(self.numobs))
     magnitude = np.zeros(size)
     lidx = 0
     for mag, nobs in zip(self.mval, numobs):
         uidx = int(lidx + nobs)
         magnitude[lidx:uidx] = mag + 0.01
         lidx = uidx
     year = np.ones(size) * 1999
     self.catalogue = Catalogue.make_from_dict(
         {'magnitude': magnitude, 'year': year})
     # Create the seismicity occurrence calculator
     self.aki_ml = AkiMaxLikelihood()
开发者ID:digitalsatori,项目名称:oq-engine,代码行数:26,代码来源:aki_maximum_likelihood_test.py

示例8: plot_kmeans

def plot_kmeans(dist_m, shape_port, dat_port, dat_star, dat_kclass, ft, humfile, sonpath, base, p):

   Zdist = dist_m[shape_port[-1]*p:shape_port[-1]*(p+1)]
   extent = shape_port[1] 

   levels = [0.5,0.75,1.25,1.5,1.75,2,3]

   fig = plt.figure()
   plt.subplot(2,1,1)
   ax = plt.gca()
   plt.imshow(np.vstack((np.flipud(dat_port), dat_star)), cmap='gray',extent=[min(Zdist), max(Zdist), -extent*(1/ft), extent*(1/ft)],origin='upper')
   
   CS = plt.contourf(np.flipud(dat_kclass), levels, alpha=0.4, extent=[min(Zdist), max(Zdist), -extent*(1/ft), extent*(1/ft)],origin='upper', cmap='YlOrRd', vmin=0.5, vmax=3)   
   plt.ylabel('Horizontal distance (m)')
   plt.xlabel('Distance along track (m)')
   plt.axis('tight')

   try:
      divider = make_axes_locatable(ax)
      cax = divider.append_axes("right", size="5%", pad=0.05)
      plt.colorbar(CS, cax=cax)
   except:
      plt.colorbar()

   custom_save(sonpath,base+'class_kmeans'+str(p))
   del fig
开发者ID:csherwood-usgs,项目名称:PyHum,代码行数:26,代码来源:_pyhum_texture.py

示例9: data_reorient_udrot

def data_reorient_udrot(d, pl, ud=None, rot90=None):
    """
    """
    print >>sys.stderr, "Reorienting...",
    if (not ud is None) and (not rot90 is None):
        if ud > 0:
            d = np.flipud(d)
        if rot90 > 0:
            d = np.rot90(d, rot90)
        print >>sys.stderr, "done."
        return d
        
    ud = pl.get_val('REORIENT_CCD_FLIPUD')
    if ud == None:
        ud = pl.get_val('CORRECTION_FLIPUD')
    ud = int(ud)
    rot90 = pl.get_val('REORIENT_CCD_ROT90')
    if rot90 == None:
        rot90 = pl.get_val('CORRECTION_ROTATION')
    rot90 = int(rot90)
    if ud > 0:
        d = np.flipud(d)
    if rot90 > 0:
        d = np.rot90(d, rot90)
    print >>sys.stderr, "done."
    return d
开发者ID:Venki-Kavuri,项目名称:bopy,代码行数:26,代码来源:transform.py

示例10: to_unit

    def to_unit(self, unit):
        """Return wavelength and transmission in new wavelength units.

        If the requested units are the same as the current units, self is
        returned.

        Parameters
        ----------
        unit : `~astropy.units.Unit` or str
            Target wavelength unit.

        Returns
        -------
        wave : `~numpy.ndarray`
        trans : `~numpy.ndarray`
        """

        if unit is u.AA:
            return self.wave, self.trans

        d = u.AA.to(unit, self.wave, u.spectral())
        t = self.trans
        if d[0] > d[-1]:
            d = np.flipud(d)
            t = np.flipud(t)
        return d, t
开发者ID:sofiatti,项目名称:sncosmo,代码行数:26,代码来源:spectral.py

示例11: schedule_jobs

def schedule_jobs(job_matrix, mode='ratio'):
    job_weight = job_matrix[:, 0]
    job_length = job_matrix[:, 1]
    if mode == 'difference':
        job_metric = numpy.subtract(job_weight, job_length)
        job_matrix = numpy.vstack((job_weight, job_length, job_metric)).T
        job_matrix = job_matrix[job_matrix[:, 2].argsort()]
        job_matrix = numpy.flipud(job_matrix)

        metric_value_freq = Counter(job_matrix[:, 2])

        # Break ties between jobs using weight (i.e. higher weight goes first)
        i = 0
        for key in sorted(metric_value_freq.keys(), reverse=True):
            subarray = job_matrix[i:i + metric_value_freq[key]]
            sorted_subarray = subarray[subarray[:, 0].argsort()]
            sorted_subarray = numpy.flipud(sorted_subarray)
            job_matrix[i:i + metric_value_freq[key]] = sorted_subarray
            i += metric_value_freq[key]

    elif mode == 'ratio':
        job_metric = numpy.divide(job_weight, job_length)

        job_matrix = numpy.vstack((job_weight, job_length, job_metric)).T
        job_matrix = job_matrix[job_matrix[:, 2].argsort()]
        job_matrix = numpy.flipud(job_matrix)

    return job_matrix
开发者ID:samuelwu90,项目名称:mooc-algo2-003,代码行数:28,代码来源:_test_a1.py

示例12: testCircular

    def testCircular(self):
        g = Graph()

        op = OpLazyCC(graph=g)
        op.ChunkShape.setValue((3, 3, 1))

        vol = np.asarray(
            [
                [0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 1, 1, 1, 0, 1, 1, 1, 0],
                [0, 1, 0, 0, 0, 0, 0, 1, 0],
                [0, 1, 0, 0, 0, 0, 0, 1, 0],
                [0, 1, 0, 0, 0, 0, 0, 1, 0],
                [0, 1, 0, 0, 0, 0, 0, 1, 0],
                [0, 1, 0, 0, 0, 0, 0, 1, 0],
                [0, 1, 1, 1, 1, 1, 1, 1, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0],
            ],
            dtype=np.uint8,
        )
        vol1 = vigra.taggedView(vol, axistags="yx")
        vol2 = vigra.taggedView(vol, axistags="xy")
        vol3 = vigra.taggedView(np.flipud(vol), axistags="yx")
        vol4 = vigra.taggedView(np.flipud(vol), axistags="xy")

        for v in (vol1, vol2, vol3, vol4):
            op.Input.setValue(v)
            for x in [0, 3, 6]:
                for y in [0, 3, 6]:
                    if x == 3 and y == 3:
                        continue
                    op.Input.setDirty(slice(None))
                    out = op.Output[x : x + 3, y : y + 3].wait()
                    print(out.squeeze())
                    assert out.max() == 1
开发者ID:ilastik,项目名称:lazyflow,代码行数:35,代码来源:testOpLazyConnectedComponents.py

示例13: _interpolate_for_irf

def _interpolate_for_irf(w_orig, w_interp, mat_in):
  '''
  Interpolate matrices for the IRF calculations
  '''
  mat_interp = np.zeros([mat_in.shape[0], mat_in.shape[1], w_interp.size])

  flip = False

  if w_orig[0] > w_orig[1]:

    w_tmp = np.flipud(w_orig)
    flip = True

  else:

    w_tmp = w_orig

  for i in xrange(mat_in.shape[0]):

    for j in xrange(mat_in.shape[1]):

      if flip is True:

        rdTmp = np.flipud(mat_in[i, j, :])

      else:
        rdTmp = mat_in[i, j, :]

      f = interpolate.interp1d(x=w_tmp, y=rdTmp)
      mat_interp[i, j, :] = f(w_interp)

  return mat_interp
开发者ID:NREL,项目名称:OpenWARP,代码行数:32,代码来源:bem.py

示例14: var_border

def var_border(v, di=1, dj=1):
    """
  Border of 2d numpy array
  di,dj is the interval between points along columns and lines
  Corner points are kept even with di and dj not 1
  """

    j, i = v.shape
    if (di, dj) == (1, 1):
        xb = np.arange(2 * i + 2 * j, dtype=v.dtype)
        yb = np.arange(2 * i + 2 * j, dtype=v.dtype)

        xb[0:j] = v[:, 0]
        xb[j : j + i] = v[-1, :]
        xb[j + i : j + i + j] = np.flipud(v[:, -1])
        xb[j + i + j :] = np.flipud(v[0, :])
    else:
        # ensure corner points are kept!!
        tmp1 = v[::dj, 0]
        tmp2 = v[-1, ::di]
        tmp3 = np.flipud(v[:, -1])[::dj]
        tmp4 = np.flipud(v[0, :])[::di]
        xb = np.concatenate((tmp1, tmp2, tmp3, tmp4))

    return xb
开发者ID:jcmt,项目名称:okean,代码行数:25,代码来源:calc.py

示例15: _northup

	def _northup( self, latitude='lat' ):
		''' this works only for global grids to be downscaled flips it northup '''
		if self.ds[ latitude ][0].data < 0: # meaning that south is north globally
			self.ds[ latitude ] = np.flipud( self.ds[ latitude ] )
			# flip each slice of the array and make a new one
			flipped = np.array( [ np.flipud( arr ) for arr in self.ds[ self.variable ].data ] )
			self.ds[ self.variable ] = (('time', 'lat', 'lon' ), flipped )
开发者ID:ua-snap,项目名称:downscale,代码行数:7,代码来源:dataset.py


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