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


Python index.Index类代码示例

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


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

示例1: __init__

 def __init__(self, data=None, index=None, name=None, series=None):
     '''
     One-dimensional array with axis labels (including time series).
     
     :param data: (*array_like*) One-dimensional array data.
     :param index: (*list*) Data index list. Values must be unique and hashable, same length as data.
     :param name: (*string*) Series name.
     '''
     if series is None:
         if isinstance(data, (list, tuple)):
             data = minum.array(data)
         if index is None:
             index = range(0, len(data))
         else:
             if len(data) != len(index):
                 raise ValueError('Wrong length of index!')
         if isinstance(index, (MIArray, DimArray)):
             index = index.tolist()
         if isinstance(index, Index):
             self._index = index
         else:
             self._index = Index.factory(index)
         self._data = data
         self._series = MISeries(data.array, self._index._index, name)
     else:
         self._series = series
         self._data = MIArray(self._series.getData())
         self._index = Index.factory(index=self._series.getIndex())
开发者ID:meteoinfo,项目名称:MeteoInfoLab,代码行数:28,代码来源:series.py

示例2: vectorial_search

def vectorial_search(querystring, collection_index, weight_type):
    """
    Recherche vectorielle de `querystring` dans `collection_index` en utilisant les poids
    de type `weight_type`. Renvoie les résultats de similarité > 0 (ordonnées par similarité)
    """
    search_results = []  # Resultat de la recherche

    # On indexe la recherche et on crée son vecteur
    query_doc = QueryDocument(querystring)
    query_index = Index([query_doc])
    # On calcule le vecteur de la query par rappport a l'index de la collection
    query_vector = query_index.get_document_vector(query_doc.id, weight_type, collection_index)

    # On calcule la similarité entre la query et chaque document de la collection
    for doc_id in collection_index.documents_ids:
        doc_vector = collection_index.get_document_vector(doc_id, weight_type)
        similarity = cosinus_similarity(query_vector, doc_vector)
        search_result = SearchResult(doc_id, similarity)
        search_results.append(search_result)

    # On trie nos resultats par ordre decroissant de similarité
    search_results = sorted(search_results, key=lambda result: -result.similarity)

    # On revoie les résultats qui ont une similarité d'au moins 15%
    # J'ai tester differents minimus de similarité et 15% semble etre celui donnant
    # filtrant le mieux les resultats (pour les query de reference du dataset)
    return [result for result in search_results if result.similarity > 0.15]
开发者ID:rcatajar,项目名称:recherche-web-ecp,代码行数:27,代码来源:vectorial_search.py

示例3: build_index

def build_index(url, depth):
    index = Index()
    crawler = CustomCrawler(url, depth, index)
    crawler.crawl_all_links()
    index.status()
    print("Страниц просмотрено %d" % len(crawler.visited))
    return index
开发者ID:nkartashov,项目名称:NKrawler,代码行数:7,代码来源:main.py

示例4: parseCreateTableString

	def parseCreateTableString(self, createTableString):
		createTablePattern = re.compile('CREATE TABLE `(?P<name>[a-z_]+)` \((?P<columns>.*?)\) ENGINE=(?P<engine>[a-z]+) (AUTO_INCREMENT=(?P<autoincrement>\d+) )?DEFAULT CHARSET=(?P<charset>[a-z\d]+)',
				re.IGNORECASE | re.DOTALL)
		matches = createTablePattern.match(createTableString)

		if matches is None:
			print "Error:\n" + createTableString

		columns = matches.group('columns').strip().split("\n")
		for index, column in enumerate(columns):
			column = column.strip()
			column = column.strip(',')

			primaryKeyMatch = re.match("^(PRIMARY KEY \((?P<columns>.*)\))", column)
			uniqueKeyMatch = re.match("^(UNIQUE KEY `(?P<key_name>.*?)` \((?P<columns>.*)\))", column)
			keyMatch = re.match("^(KEY `(?P<key_name>.*?)` \((?P<columns>.*)\))", column)

			if primaryKeyMatch is not None:
				indexColumns = self.columnStringsToObjects(Index.parseColumnNamesFromString(primaryKeyMatch.group('columns')))
				self.indexes.append(Index('PRIMARY', 'PRIMARY', indexColumns))
			elif uniqueKeyMatch is not None:
				indexColumns = self.columnStringsToObjects(Index.parseColumnNamesFromString(uniqueKeyMatch.group('columns')))
				self.indexes.append(Index('UNIQUE', uniqueKeyMatch.group('key_name'), indexColumns))
			elif keyMatch is not None:
				indexColumns = self.columnStringsToObjects(Index.parseColumnNamesFromString(keyMatch.group('columns')))
				self.indexes.append(Index('KEY', keyMatch.group('key_name'), indexColumns))
			else:
				self.columns.append(Column.fromString(column))

		self.name = matches.group('name')
		self.autoincrement = matches.group('autoincrement')
开发者ID:Fapiko,项目名称:pyHeidi,代码行数:31,代码来源:table.py

示例5: get_gradient

def get_gradient(im, index, border_thickness_steps):
    """
    Fun. calc. radial gradient including thickness of cell edges
    @param im: image (for which grad. will be calc.)
    @param index: indices of pixes sorted by polar coords. (alpha, radius) 
    @param border_thickness_steps: number of steps to cop. grad. - depands on cell border thickness
    @return: gradient matrix for cell
    """
    # index of axis used to find max grad.
    # PL: Indeks pomocniczy osi służący do wyznaczenia maksymalnego gradientu
    max_gradient_along_axis = 2
    # preparing the image limits (called subimage) for which grad. will be computed
    # PL: Wymiary wycinka obrazu, dla którego będzie obliczany gradient
    radius_lengths, angles = index.shape[0], index.shape[1]
    # matrix init
    # for each single step for each border thick. separated grad. is being computed
    # at the end the max. grad values are returned (for all steps and thick.)
    # PL: Inicjacja macierzy dla obliczania gradientów
    # PL: Dla każdego pojedynczego kroku dla zadanej grubości krawędzi komórki obliczany jest osobny gradient
    # PL: Następnie zwracane są maksymalne wartości gradientu w danym punkcie dla wszystkich kroków grubości krawędzi
    gradients_for_steps = np.zeros((radius_lengths, angles, border_thickness_steps), dtype=np.float64)
    # PL: Dla każdego kroku wynikającego z grubości krawędzi komórki:
    # PL: Najmniejszy krok ma rozmiar 1, największy ma rozmiar: ${border_thickness_steps}
    for border_thickness_step in range(1, int(border_thickness_steps) + 1):

        # find beg. and end indices of input matrix for which the gradient will be computed
        # PL: Wyznacz początek i koniec wycinka macierzy, dla którego będzie wyliczany gradient
        matrix_end = radius_lengths - border_thickness_step
        matrix_start = border_thickness_step

        # find beg. and end indices of pix. for which the gradient will be computed
        # PL: Wyznacz początek i koniec wycinka indeksu pikseli, dla którego będzie wyliczany gradient
        starting_index = index[:matrix_end, :]
        ending_index = index[matrix_start:, :]

        # find the spot in matrix where comp. gradient will go
        # PL: Wyznacz początek i koniec wycinka macierzy wynikowej, do którego będzie zapisany obliczony gradient
        intersect_start = int(math.ceil(border_thickness_step / 2.0))
        intersect_end = int(intersect_start + matrix_end)

        # comp. current gradient for selected (sub)image 
        # PL: Wylicz bieżącą wartość gradientu dla wyznaczonego wycinka obrazu
        try:
            current_step_gradient = im[Index.to_numpy(ending_index)] - im[Index.to_numpy(starting_index)]
        except Exception:
            print border_thickness_step
            print radius_lengths
            print matrix_start
            print matrix_end
            print ending_index
            print starting_index

            raise Exception

        current_step_gradient /= np.sqrt(border_thickness_step)
        # Zapisz gradient do wyznaczonego wycinka macierzy wyników
        gradients_for_steps[intersect_start:intersect_end, :, border_thickness_step-1] = current_step_gradient

    return gradients_for_steps.max(axis=max_gradient_along_axis)
开发者ID:AnneCarpenter,项目名称:cellstar,代码行数:59,代码来源:calc_util.py

示例6: test1

 def test1(self):
     con = make_dbcon()
     ds = DataStore(con)
     col = ds.collection("users")
     
     i = Index(con, col, 'email')
     
     self.assertEqual(i.name(), 'email')
开发者ID:stereohead,项目名称:wsgi-cahin,代码行数:8,代码来源:tests.py

示例7: init

 def init(self, *file):
     self.rules      = [] 
     self.if_index   = Index().init() 
     self.then_index = Index().init()
     
     if file:
         self.load_rules(file[0])
     return self
开发者ID:asottile,项目名称:ancient-pythons,代码行数:8,代码来源:kbase.py

示例8: initialize

def initialize(facts, kbase):
    known = Index().init()
    for fact in facts:
        known.store(fact, (fact, 'initial'))          # fact, proof
    known.store(['true'], (['true'], 'atomic'))       # if true then...

    for rule in kbase.rules:
        rule['trigger'] = 0 
    return known
开发者ID:asottile,项目名称:ancient-pythons,代码行数:9,代码来源:forward.py

示例9: test_mark_task_done

 def test_mark_task_done(self):
     now = datetime.datetime.now()
     newTask = self.index.addTask("new task", now, "NONE")
     taskWithDate, taskWithoutDates = self.index.listAll()
     self.assertEqual(len(taskWithDate), 3)
     self.assertEqual(len(taskWithoutDates), 1)
     updatedTask = self.index.markTaskComplete(newTask.id)
     self.assertEqual(updatedTask.status, "DONE")
     index = Index()
     deltedTask = index.findTaskById(updatedTask.id)
     self.assertIsNone(deltedTask)
开发者ID:sajja,项目名称:mytask,代码行数:11,代码来源:tasktest.py

示例10: load_index

def load_index(index_path, train_path, reconstruct=Setting.RERUN):
    print "load or construct index..."
    if not reconstruct and os.path.exists(index_path):
        index = load_data(index_path)
    else:
        index = Index()
        index.train_path = train_path
        index.construct_index()
        dump_data(index, index_path)
    print "done!"
    return index
开发者ID:fairypp,项目名称:facebook_check_in_prediction,代码行数:11,代码来源:axis_kde.py

示例11: test_should_store_tokens_lowercase

 def test_should_store_tokens_lowercase(self):
     index = Index()
     index.add_document('doc', 'This IS mY firsT DoCuMeNt')
     expected_tokens = set(['this', 'is', 'my', 'first', 'document'])
     expected_index = {'this': set(['doc']),
                       'is': set(['doc']),
                       'my': set(['doc']),
                       'first': set(['doc']),
                       'document': set(['doc']),}
     self.assertEquals(index.tokens(), expected_tokens)
     self.assertEquals(dict(index._index), expected_index)
开发者ID:sergio-garcia-clones,项目名称:nlplaying,代码行数:11,代码来源:test_index.py

示例12: test_pending_task_could_be_snoozed

    def test_pending_task_could_be_snoozed(self):
        today = datetime.datetime.today()
        today_10_min_future = today + datetime.timedelta(minutes=10)

        self.addTask(6, "task statring in 10 min", "PENDING", today_10_min_future.strftime('%Y-%m-%d %H:%M'), "NONE")
        overdue, startingsoon = self.index.listNotificationsPendingTasks()
        self.assertEqual(len(startingsoon), 1)
        self.index.snooze(6)
        index = Index()
        overdue, startingsoon = index.listNotificationsPendingTasks()
        self.assertEqual(len(startingsoon), 0)
开发者ID:sajja,项目名称:mytask,代码行数:11,代码来源:tasktest.py

示例13: Repository

class Repository(object):
    '''
    The git repository
    '''

    GIT_DIR = '.git'
    
    INIT_DIR = [
        'branches',
        'hooks',
        'info',
        'objects',
        'objects/info',
        'objects/pack',
        'refs',
        'refs/heads',
        'refs/tags',
    ]
    
    INIT_FILE = [
        ['HEAD', 'ref: refs/heads/master'],
        ['description', 'Unnamed repository'],
        ['info/exclude', ''],
    ]
    
    
    def __init__(self, workspace):
        self.workspace = workspace
        self.index = Index(os.path.join(workspace, '.git', 'index'))
        self.config = Config(workspace)
        self.head_path = self._get_head_path()
        self.head_tree = None
        if os.path.exists(self.head_path):
            self.head_tree = read_file(self.head_path).strip()
    
    def _get_head_path(self):
        branch_name = read_file(os.path.join(self.workspace, '.git', 'HEAD')).strip('\n').rsplit('/', 1)[-1]
        return os.path.join(self.workspace, '.git', 'refs', 'heads', branch_name)
        
    def stage(self, files):
        try:
            for file in files:
                content = read_file(file)
                blob = Blob(self.workspace, content)
                if not os.path.exists(blob.path):
                    write_object_to_file(blob.path, blob.content)
                stat = os.stat(os.path.join(self.workspace, file))
                self.index.add_entry(file, ctime=stat.st_ctime, mtime=stat.st_mtime, dev=stat.st_dev, ino=stat.st_ino, mode=cal_mode(stat.st_mode), \
                       uid=stat.st_uid, gid=stat.st_gid, size=stat.st_size,sha1=blob.sha1, flags=0)
            self.index.write_to_file()
                    
        except Exception, e:
            print 'stage file %s error: %s' % (file, e)
开发者ID:bearxwbyr,项目名称:git-in-python,代码行数:53,代码来源:repository.py

示例14: call_index

def call_index():
	global par_orb,par_color
	path= z.get()
	if path== '':
		tkMessageBox.showinfo('ERROR','Please folder path!!!')
	elif path != '':
		if par_orb==1:
			di=Data_index(path)
			di.insert_data()
		elif par_color==1:
			i=Index(path)
			i.main_fun()
开发者ID:farhan0581,项目名称:CBIR,代码行数:12,代码来源:main.py

示例15: __init__

 def __init__(self, data=None, index=None, columns=None, dataframe=None):                             
     if dataframe is None:
         if not data is None:
             if isinstance(data, dict):
                 columns = data.keys()
                 dlist = []
                 n = 1
                 for v in data.values():
                     if isinstance(v, (list, tuple)):
                         n = len(v)
                         v = minum.array(v)                    
                     elif isinstance(v, MIArray):
                         n = len(v)
                     dlist.append(v)
                 for i in range(len(dlist)):
                     d = dlist[i]
                     if not isinstance(d, MIArray):
                         d = [d] * n
                         d = minum.array(d)
                         dlist[i] = d
                 data = dlist
                 
             if isinstance(data, MIArray):
                 n = len(data)
                 data = data.array
             else:
                 dlist = []
                 n = len(data[0])
                 for dd in data:
                     dlist.append(dd.array)
                 data = dlist
                     
             if index is None:
                 index = range(0, n)
             else:
                 if n != len(index):
                     raise ValueError('Wrong length of index!')
                     
         if isinstance(index, (MIArray, DimArray)):
             index = index.tolist()
             
         if isinstance(index, Index):
             self._index = index
         else:
             self._index = Index.factory(index)
         if data is None:
             self._dataframe = MIDataFrame(self._index._index)
         else:
             self._dataframe = MIDataFrame(data, self._index._index, columns)
     else:
         self._dataframe = dataframe
         self._index = Index.factory(index=self._dataframe.getIndex())
开发者ID:meteoinfo,项目名称:MeteoInfoLab,代码行数:52,代码来源:dataframe.py


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