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


Python numpy.lexsort函数代码示例

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


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

示例1: VtuMatchLocationsArbitrary

def VtuMatchLocationsArbitrary(vtu1, vtu2, tolerance=1.0e-6):
    """
  Check that the locations in the supplied vtus match, returning True if they
  match and False otherwise.
  The locations may be in a different order.
  """

    locations1 = vtu1.GetLocations()
    locations2 = vtu2.GetLocations()
    if not locations1.shape == locations2.shape:
        return False

    epsilon = numpy.ones(locations1.shape[1]) * numpy.finfo(numpy.float).eps
    for j in range(locations1.shape[1]):
        epsilon[j] = epsilon[j] * (locations1[:, j].max() - locations1[:, j].min())

    for i in range(len(locations1)):
        for j in range(len(locations1[i])):
            if abs(locations1[i][j]) < epsilon[j]:
                locations1[i][j] = 0.0
            if abs(locations2[i][j]) < epsilon[j]:
                locations2[i][j] = 0.0

    # lexical sort on x,y and z coordinates resp. of locations1 and locations2
    sort_index1 = numpy.lexsort(locations1.T)
    sort_index2 = numpy.lexsort(locations2.T)

    # should now be in same order, so we can check for its biggest difference
    return abs(locations1[sort_index1] - locations2[sort_index2]).max() < tolerance
开发者ID:kessel,项目名称:ipbs,代码行数:29,代码来源:vtktools.py

示例2: test_sort_index_multicolumn

    def test_sort_index_multicolumn(self):
        import random
        A = np.arange(5).repeat(20)
        B = np.tile(np.arange(5), 20)
        random.shuffle(A)
        random.shuffle(B)
        frame = DataFrame({'A': A, 'B': B,
                           'C': np.random.randn(100)})

        # use .sort_values #9816
        with tm.assert_produces_warning(FutureWarning):
            frame.sort_index(by=['A', 'B'])
        result = frame.sort_values(by=['A', 'B'])
        indexer = np.lexsort((frame['B'], frame['A']))
        expected = frame.take(indexer)
        assert_frame_equal(result, expected)

        # use .sort_values #9816
        with tm.assert_produces_warning(FutureWarning):
            frame.sort_index(by=['A', 'B'], ascending=False)
        result = frame.sort_values(by=['A', 'B'], ascending=False)
        indexer = np.lexsort((frame['B'].rank(ascending=False),
                              frame['A'].rank(ascending=False)))
        expected = frame.take(indexer)
        assert_frame_equal(result, expected)

        # use .sort_values #9816
        with tm.assert_produces_warning(FutureWarning):
            frame.sort_index(by=['B', 'A'])
        result = frame.sort_values(by=['B', 'A'])
        indexer = np.lexsort((frame['A'], frame['B']))
        expected = frame.take(indexer)
        assert_frame_equal(result, expected)
开发者ID:AlexisMignon,项目名称:pandas,代码行数:33,代码来源:test_sorting.py

示例3: test_cutting_plane_selector

def test_cutting_plane_selector():
    # generate fake data with a number of non-cubical grids
    ds = fake_random_ds(64, nprocs=51)
    assert all(ds.periodicity)

    # test cutting plane against orthogonal plane
    for i, d in enumerate("xyz"):
        norm = np.zeros(3)
        norm[i] = 1.0

        for coord in np.arange(0, 1.0, 0.1):
            center = np.zeros(3)
            center[i] = coord

            data = ds.slice(i, coord)
            data.get_data()
            data2 = ds.cutting(norm, center)
            data2.get_data()

            assert data.shape[0] == data2.shape[0]

            cells1 = np.lexsort((data["x"], data["y"], data["z"]))
            cells2 = np.lexsort((data2["x"], data2["y"], data2["z"]))
            for d2 in "xyz":
                yield assert_equal, data[d2][cells1], data2[d2][cells2]
开发者ID:danielgrassinger,项目名称:yt_new_frontend,代码行数:25,代码来源:test_selectors.py

示例4: negative_gradient

    def negative_gradient(self, y_true, y_pred, sample_group=None, **kargs):
        y_pred = y_pred.ravel()
        # the lambda terms
        grad = np.empty_like(y_true, dtype=np.float64)

        # for updating terminal regions
        self.weights = np.empty_like(y_true, dtype=np.float64)

        if sample_group is None:
            ix = np.lexsort((y_true, -y_pred))
            inv_ix = np.empty_like(ix)
            inv_ix[ix] = np.arange(len(ix))
            tmp_grad, tmp_weights = _lambda(y_true[ix], y_pred[ix],
                                            self.max_rank)
            grad = tmp_grad[inv_ix]
            self.weights = tmp_weights[inv_ix]
        else:
            for start, end in self._groupby(sample_group):
                ix = np.lexsort((y_true[start:end], -y_pred[start:end]))
                inv_ix = np.empty_like(ix)
                inv_ix[ix] = np.arange(len(ix))

                # sort by current score before passing
                # and then remap the return values
                tmp_grad, tmp_weights = _lambda(y_true[ix + start],
                                                y_pred[ix + start],
                                                self.max_rank)
                grad[start:end] = tmp_grad[inv_ix]
                self.weights[start:end] = tmp_weights[inv_ix]

        return grad
开发者ID:justheuristic,项目名称:l2rank,代码行数:31,代码来源:lambdamart.py

示例5: set_sort_col

 def set_sort_col(self, col_index, add=False):
     '''Set the column to sort this table by. If add is true, this column
     will be added to the end of the existing sort order (or removed from the
     sort order if it is already present.)
     '''
     if not add:
         if len(self.sortcols)>0 and col_index in self.sortcols:
             # If this column is already sorted, flip it
             self.row_order = self.row_order[::-1]
             self.sortdir = -self.sortdir
         else:
             self.sortdir = 1
             self.sortcols = [col_index]
             # If this column hasn't been sorted yet, then sort descending
             self.row_order = np.lexsort(self.data[:,self.col_order][:,self.sortcols[::-1]].T.tolist())
     else:
         if len(self.sortcols)>0 and col_index in self.sortcols:
             self.sortcols.remove(col_index)
         else:
             self.sortcols += [col_index]
         if self.sortcols==[]:
             # if all sort columns have been toggled off, reset row_order
             self.row_order = np.arange(self.data.shape[0])
         else:
             self.row_order = np.lexsort(self.data[:,self.sortcols[::-1]].T.tolist())
     self.ordered_data = self.data[self.row_order,:][:,self.col_order]
开发者ID:chadchouGitHub,项目名称:CellProfiler-Analyst,代码行数:26,代码来源:tableviewer.py

示例6: preCompute

def preCompute(rowBased_row_array,rowBased_col_array,S_rowBased_data_array):
    """
    format affinity/similarity matrix
    """
    
    # Get parameters
    data_len=len(S_rowBased_data_array)
    row_indptr=sparseAP_cy.getIndptr(rowBased_row_array)
    if row_indptr[-1]!=data_len: row_indptr=np.concatenate((row_indptr,np.array([data_len])))
    row_to_col_ind_arr=np.lexsort((rowBased_row_array,rowBased_col_array))
    colBased_row_array=sparseAP_cy.npArrRearrange_int_para(rowBased_row_array,row_to_col_ind_arr)
    colBased_col_array=sparseAP_cy.npArrRearrange_int_para(rowBased_col_array,row_to_col_ind_arr)
    col_to_row_ind_arr=np.lexsort((colBased_col_array,colBased_row_array))
    col_indptr=sparseAP_cy.getIndptr(colBased_col_array)
    if col_indptr[-1]!=data_len: col_indptr=np.concatenate((col_indptr,np.array([data_len])))
    kk_col_index=sparseAP_cy.getKKIndex(colBased_row_array,colBased_col_array)
    
    #Initialize matrix A, R
    A_rowbased_data_array=np.array([0.0]*data_len)
    R_rowbased_data_array=np.array([0.0]*data_len)
    
    #Add random samll value to remove degeneracies
    random_state=np.random.RandomState(0)
    S_rowBased_data_array+=1e-12*random_state.randn(data_len)*(np.amax(S_rowBased_data_array)-np.amin(S_rowBased_data_array))
    
    #Convert row_to_col_ind_arr/col_to_row_ind_arr data type to np.int datatype so it is compatible with cython code
    row_to_col_ind_arr=row_to_col_ind_arr.astype(np.int)
    col_to_row_ind_arr=col_to_row_ind_arr.astype(np.int)
    
    return S_rowBased_data_array, A_rowbased_data_array, R_rowbased_data_array,col_indptr,row_indptr,row_to_col_ind_arr,col_to_row_ind_arr,kk_col_index
开发者ID:bioinfocao,项目名称:pysapc,代码行数:30,代码来源:sparseMatrixPrepare.py

示例7: fullCheck

    def fullCheck(self,a):
        # Check that atoms repeats over a
        bp1, bp2, bp3 = self.bp1, self.bp2, self.bp3 
        atomtypes = N.unique(self.snr)
        passed = True
        for atomtype in atomtypes:
            sameatoms = N.argwhere(self.snr==atomtype)
            samexyz = self.xyz[sameatoms]
            samexyz = samexyz.reshape((-1, 3))
            shifted = samexyz+a.reshape((1,3))
            
            # Move inside PBC
            samexyz = moveIntoCell(samexyz,self.pbc[0,:],self.pbc[1,:],self.pbc[2,:],self.accuracy)
            shifted = moveIntoCell(shifted,self.pbc[0,:],self.pbc[1,:],self.pbc[2,:],self.accuracy)

            # Should be the same if sorted!
            ipiv = N.lexsort(N.round(N.transpose(samexyz)/self.accuracy))
            samexyz = samexyz[ipiv,:]
            ipiv = N.lexsort(N.round(N.transpose(shifted)/self.accuracy))
            shifted = shifted[ipiv,:]
            
            if not N.allclose(samexyz,shifted,atol=self.accuracy):
                passed = False
            
        return passed
开发者ID:mpn2,项目名称:Inelastica,代码行数:25,代码来源:Symmetry.py

示例8: loc_vector_labels

def loc_vector_labels(x):
    """Identify unique labels from the vector of image labels
    
    x - a vector of one label or dose per image
    
    returns labels, labnum, uniqsortvals
    labels - a vector giving an ordinal per image where that ordinal
             is an index into the vector of unique labels (uniqsortvals)
    labnum - # of unique labels in x
    uniqsortvals - a vector containing the unique labels in x
    """
    #
    # Get the index of each image's label in the sorted array
    #
    order = np.lexsort((x,))
    reverse_order = np.lexsort((order,))
    #
    # Get a sorted view of the labels
    #
    sorted_x = x[order]
    #
    # Find the elements that start a new run of labels in the sorted array
    # ex: 0,0,0,3,3,3,5,5,5
    #     1,0,0,1,0,0,1,0,0
    #
    # Then cumsum - 1 turns into:
    #     0,0,0,1,1,1,2,2,2
    #
    # and sorted_x[first_occurrence] gives the unique labels in order
    first_occurrence = np.ones(len(x), bool)
    first_occurrence[1:] = sorted_x[:-1] != sorted_x[1:]
    sorted_labels = np.cumsum(first_occurrence) - 1
    labels = sorted_labels[reverse_order]
    uniqsortvals = sorted_x[first_occurrence]
    return (labels, len(uniqsortvals), uniqsortvals)
开发者ID:sanuj,项目名称:CellProfiler,代码行数:35,代码来源:calculatestatistics.py

示例9: test_03_01_graph

    def test_03_01_graph(self):
        '''Make a simple graph'''
        #
        # The skeleton looks something like this:
        #
        #   .   .
        #    . .
        #     .
        #     .
        i,j = np.mgrid[-10:11,-10:11]
        skel = (i < 0) & (np.abs(i) == np.abs(j))
        skel[(i >= 0) & (j == 0)] = True
        #
        # Put a single label at the bottom
        #
        labels = np.zeros(skel.shape, int)
        labels[(i > 8) & (np.abs(j) < 2)] = 1
        np.random.seed(31)
        intensity = np.random.uniform(size = skel.shape)
        workspace, module = self.make_workspace(
            labels, skel, intensity_image = intensity, wants_graph = True)
        module.run(workspace)
        edge_graph = self.read_graph_file(EDGE_FILE)
        vertex_graph = self.read_graph_file(VERTEX_FILE)
        vidx = np.lexsort((vertex_graph["j"], vertex_graph["i"]))
        #
        # There should be two vertices at the bottom of the array - these
        # are bogus artifacts of the object hitting the edge of the image
        #
        for vidxx in vidx[-2:]:
            self.assertEqual(vertex_graph["i"][vidxx], 20)
        vidx = vidx[:-2]
        
        expected_vertices = ((0,0), (0,20), (10,10), (17,10))
        self.assertEqual(len(vidx), len(expected_vertices))
        for idx, v in enumerate(expected_vertices):
            vv = vertex_graph[vidx[idx]]
            self.assertEqual(vv["i"], v[0])
            self.assertEqual(vv["j"], v[1])

        #
        # Get rid of edges to the bogus vertices
        #
        for v in ("v1","v2"):
            edge_graph = edge_graph[vertex_graph["i"][edge_graph[v]-1] != 20]
            
        eidx = np.lexsort((vertex_graph["j"][edge_graph["v1"]-1],
                           vertex_graph["i"][edge_graph["v1"]-1],
                           vertex_graph["j"][edge_graph["v2"]-1],
                           vertex_graph["i"][edge_graph["v2"]-1]))
        expected_edges = (((0,0),(10,10),11, np.sum(intensity[(i <= 0) & (j<=0) & skel])),
                          ((0,20),(10,10),11, np.sum(intensity[(i <= 0) & (j>=0) & skel])),
                          ((10,10),(17,10),8, np.sum(intensity[(i >= 0) & (i <= 7) & skel])))
        for i, (v1, v2, length, total_intensity) in enumerate(expected_edges):
            ee = edge_graph[eidx[i]]
            for ve, v in ((v1, ee["v1"]), (v2, ee["v2"])):
                self.assertEqual(ve[0], vertex_graph["i"][v-1])
                self.assertEqual(ve[1], vertex_graph["j"][v-1])
            self.assertEqual(length, ee["length"])
            self.assertAlmostEqual(total_intensity, ee["total_intensity"], 4)
开发者ID:drmono,项目名称:CellProfiler,代码行数:60,代码来源:test_measureneurons.py

示例10: sortrowsByMultiCol

def sortrowsByMultiCol(data, list_sortCol, isAscending=1):
    """
    Sort 2D numpy array by multiple columns
    :param data:
    :param list_sortCol: e.g. [0, 2, 3], 1st element is most important column to sort, 2nd element is 2nd most important, etc.
    :return: sorted data
    """
    # data_sort = data # data_sort has to be number
    # k_col = len(list_sortCol)-1
    # while k_col >= 0:
    #     idx_col = list_sortCol[k_col]
    #     t_data = np.float64(data_sort[:,idx_col])
    #     if isAscending==1:
    #         data_sort = data_sort[t_data.argsort(),:]
    #     elif isAscending==0:
    #         data_sort = data_sort[(-t_data).argsort(),:] # descending order
    #     k_col -= 1

    dataForSort = np.transpose(data[:, list_sortCol[::-1]])  # [start:stop:step] -1 is meant to reverse the order
    if isAscending == 1:
        idx_sort = np.lexsort(dataForSort)  # last row in dataForSort is most important to sort
    elif isAscending == 0:
        idx_sort = np.lexsort(-dataForSort)  # last row in dataForSort is most important to sort

    data_sorted = data[idx_sort, :]

    return data_sorted
开发者ID:YutaAsano1986,项目名称:GitExample,代码行数:27,代码来源:fnc_math.py

示例11: pearson_correlation

def pearson_correlation(movie_id_1, movie_id_2):
    rated_movie1 = ratings[ratings[:, 1] == movie_id_1]
    rated_movie2 = ratings[ratings[:, 1] == movie_id_2]
    rated_both = np.intersect1d(rated_movie1[:, 0], rated_movie2[:, 0], True)

    if len(rated_both) < 15:
        return 0

    ratings_movie1 = rated_movie1[np.in1d(rated_movie1[:, 0], rated_both), :]
    ratings_movie2 = rated_movie2[np.in1d(rated_movie2[:, 0], rated_both), :]
    sorted_movie1 = ratings_movie1[np.lexsort((ratings_movie1[:, 0], ))][:, [0, 2]]
    sorted_movie2 = ratings_movie2[np.lexsort((ratings_movie2[:, 0], ))][:, [0, 2]]

    mean1 = np.mean(ratings_movie1[:, 2])
    mean2 = np.mean(ratings_movie2[:, 2])

    numerator = 0
    denomX = 0
    denomY = 0
    for i in range(len(sorted_movie1)):
        x = sorted_movie1[i][1] - mean1
        y = sorted_movie2[i][1] - mean2
        numerator += x * y
        denomX += x * x
        denomY += y * y

    if (denomX == 0 or denomY == 0):
        return 0

    return round(numerator / m.sqrt(denomX * denomY), 3)
开发者ID:DarthKipsu,项目名称:machine-learning,代码行数:30,代码来源:problem4.py

示例12: test_hemisphere_subdivide

def test_hemisphere_subdivide():

    def flip(vertices):
        x, y, z = vertices.T
        f = (z < 0) | ((z == 0) & (y < 0)) | ((z == 0) & (y == 0) & (x < 0))
        return 1 - 2*f[:, None]

    decimals = 6
    # Test HemiSphere.subdivide
    # Create a hemisphere by dividing a hemi-icosahedron
    hemi1 = HemiSphere.from_sphere(unit_icosahedron).subdivide(4)
    vertices1 = np.round(hemi1.vertices, decimals)
    vertices1 *= flip(vertices1)
    order = np.lexsort(vertices1.T)
    vertices1 = vertices1[order]

    # Create a hemisphere from a subdivided sphere
    sphere = unit_icosahedron.subdivide(4)
    hemi2 = HemiSphere.from_sphere(sphere)
    vertices2 = np.round(hemi2.vertices, decimals)
    vertices2 *= flip(vertices2)
    order = np.lexsort(vertices2.T)
    vertices2 = vertices2[order]

    # The two hemispheres should have the same vertices up to their order
    nt.assert_array_equal(vertices1, vertices2)

    # Create a hemisphere from vertices
    hemi3 = HemiSphere(xyz=hemi1.vertices)
    nt.assert_array_equal(hemi1.faces, hemi3.faces)
    nt.assert_array_equal(hemi1.edges, hemi3.edges)
开发者ID:JDWarner,项目名称:dipy,代码行数:31,代码来源:test_sphere.py

示例13: sortContours2

def sortContours2( contours, direction = "x" ):#TODO
    contourPoints = np.zeros((len(contours),2), dtype = int)
    if direction == "x":
        a = 1
        b = 0
    elif direction == "y":
        a = 0
        b = 1
    
    counter = 0
    for cnt in contours:
        conResh = np.reshape(cnt,(-1,2))
        idx = np.lexsort( (conResh[:,a],conResh[:,b]) )
        sortedContours = conResh[idx,:]
        contourPoints[counter,:] = sortedContours[0,:] # The coordinate of reference point.
        counter = counter + 1
        
    sortedIdx = np.lexsort((contourPoints[:,a], contourPoints[:,b]))
    sortedContours = []
    referencePoints = []
    for idx in sortedIdx:
        sortedContours.append(contours[idx])
        referencePoints.append(contourPoints[idx])
        
    return sortedContours, referencePoints
开发者ID:tf-czu,项目名称:EFD,代码行数:25,代码来源:contours.py

示例14: doubleParetoSorting

def doubleParetoSorting(x0, x1):
    fronts = [[]]
    left = [[]]
    right = [[]]
    idx = np.lexsort((x1, x0))
    
    idxEdge = np.lexsort((-np.square(x0-0.5), x1))
    
    fronts[-1].append(idxEdge[0])
    left[-1].append(x0[idxEdge[0]])
    right[-1].append(x0[idxEdge[0]])
    for i0 in idxEdge[1:]:
        if x0[i0]>=left[-1] and x0[i0]<=right[-1]:
            #add a new front
            fronts.append([])
            left.append([])
            right.append([])
            fronts[-1].append(i0)
            left[-1].append(x0[i0])
            right[-1].append(x0[i0])
        else:
            #check existing fonts
            for i1 in range(len(fronts)):
                if x0[i0]<left[i1] or x0[i0]>right[i1]:
                    if x0[i0]<left[i1]:
                        left[i1] = x0[i0]
                        fronts[i1].insert(0, i0)
                    else:
                        right[i1] = x0[i0]
                        fronts[i1].append(i0)
                    break    
    return (fronts, idx)
开发者ID:JosePedroMatos,项目名称:ADAPT-DB,代码行数:32,代码来源:domination.py

示例15: ssea_ranker

def ssea_ranker (ssea_list, q_val_cutoff, peak_type):
    if peak_type == "Amplification":
        sign = 1
    elif peak_type == "Deletion":
        sign = -1
    
    thresh=(ssea_list[:,1]<q_val_cutoff).astype(int)
    sign_adj = ssea_list*sign
    rank_big=np.lexsort((thresh, -sign_adj[:,0]))
    ranks_ranked = []
    for x in enumerate(rank_big):
        ranks_ranked.append(x)
    ranked = np.array(ranks_ranked)
    
    ranked_sorted = ranked[np.lexsort([ranked[:,0], ranked[:,1]])]
    ranks = []
    for x in ranked_sorted:
        ranks.append(x[0])
    
    
    ranks_out = []
    for x in xrange(len(ssea_list[:,0])):
        if thresh[x]==1: 
            ranks_out.append(ranks[x])
        else:
            ranks_out.append('not significant')
    return ranks_out
开发者ID:yniknafs-mctp,项目名称:scripts,代码行数:27,代码来源:gistic_main_sets_parallel.py


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