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


Python collections.intersect函数代码示例

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


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

示例1: testEmptyIntersection

    def testEmptyIntersection(self):
        values, ix1, ix2 = collections.intersect([1, 2, 3], [4, 5, 6])
        self.assertEqual(len(values), 0)
        self.assertEqual(len(ix1), 0)
        self.assertEqual(len(ix2), 0)

        values, ix1, ix2 = collections.intersect([], [])
        self.assertEqual(len(values), 0)
        self.assertEqual(len(ix1), 0)
        self.assertEqual(len(ix2), 0)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:10,代码来源:utils_test.py

示例2: testPartialIntersectionSkipNones

    def testPartialIntersectionSkipNones(self):
        v1 = [None, 1, None, None, 2, None, 3, None, 4]
        v2 = [1, None, 2, None, 3, 4]

        values, ix1, ix2 = collections.intersect(v1, v2, True)
        self.assertEqual(values, [1, 2, 3, 4])
        self.assertEqual(ix1, [1, 4, 6, 8])
        self.assertEqual(ix2, [0, 2, 4, 5])

        values, ix2, ix1 = collections.intersect(v2, v1, True)
        self.assertEqual(values, [1, 2, 3, 4])
        self.assertEqual(ix1, [1, 4, 6, 8])
        self.assertEqual(ix2, [0, 2, 4, 5])
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:13,代码来源:utils_test.py

示例3: testPartialIntersection6

    def testPartialIntersection6(self):
        v1 = [1, 1, 2, 2, 3, 3]
        v2 = [1, 2, 3]

        values, ix1, ix2 = collections.intersect(v1, v2)
        self.assertEqual(values, [1, 2, 3])
        self.assertEqual(ix1, [0, 2, 4])
        self.assertEqual(ix2, [0, 1, 2])

        values, ix2, ix1 = collections.intersect(v2, v1)
        self.assertEqual(values, [1, 2, 3])
        self.assertEqual(ix1, [0, 2, 4])
        self.assertEqual(ix2, [0, 1, 2])
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:13,代码来源:utils_test.py

示例4: update

	def update(self):
		if self.__isDirty():
			# Search for datetime intersections between the data series,
			# but start right after the last one found.
			ds1DateTimes = self.__ds1.getDecorated().getDateTimes()
			ds2DateTimes = self.__ds2.getDecorated().getDateTimes()
			if self.__lastPos1 != None:
				ds1DateTimes = ds1DateTimes[self.__lastPos1+1:]
			if self.__lastPos2 != None:
				ds2DateTimes = ds2DateTimes[self.__lastPos2+1:]

			# Calculate the intersections.
			dateTimes, pos1, pos2 = collections.intersect(ds1DateTimes, ds2DateTimes)

			# Update each array's relative position to make them absolute positions.
			if self.__lastPos1 != None and len(pos1):
				pos1 = [self.__lastPos1 + pos + 1 for pos in pos1]
			if self.__lastPos2 != None and len(pos2):
				pos2 = [self.__lastPos2 + pos + 1 for pos in pos2]

			# Update the last intersection.
			if len(pos1):
				self.__lastPos1 = pos1[-1]
			if len(pos2):
				self.__lastPos2 = pos2[-1]

			# Update the aligned data series.
			self.__ds1.update(dateTimes, pos1)
			self.__ds2.update(dateTimes, pos2)
			self.__resetDirty()
开发者ID:jacobirwin,项目名称:pyalgotrade,代码行数:30,代码来源:dataseries.py

示例5: testPartialIntersection2

 def testPartialIntersection2(self):
     values, ix1, ix2 = collections.intersect([1, 2, 4], [1, 2, 3])
     self.assertEqual(len(values), 2)
     self.assertEqual(values[0], 1)
     self.assertEqual(values[1], 2)
     self.assertEqual(ix1[0], 0)
     self.assertEqual(ix1[1], 1)
     self.assertEqual(ix2[0], 0)
     self.assertEqual(ix2[1], 1)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:9,代码来源:utils_test.py

示例6: testFullIntersectionWithDateTimes

    def testFullIntersectionWithDateTimes(self):
        size = 1000
        dateTimes1 = []
        dateTimes2 = []
        now = datetime.datetime.now()
        for i in xrange(size):
            dateTimes1.append(now + datetime.timedelta(seconds=i))
            dateTimes2.append(now + datetime.timedelta(seconds=i))

        self.assertEqual(dateTimes1, dateTimes2)

        values, ix1, ix2 = collections.intersect(dateTimes1, dateTimes2)
        self.assertEqual(values, dateTimes1)
        self.assertEqual(values, dateTimes2)
        self.assertEqual(ix1, list(range(size)))
        self.assertEqual(ix1, ix2)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:16,代码来源:utils_test.py

示例7: testFullIntersection

 def testFullIntersection(self):
     values, ix1, ix2 = collections.intersect([1, 2, 3], [1, 2, 3])
     self.assertEqual(len(values), 3)
     self.assertEqual(len(ix1), 3)
     self.assertEqual(len(ix2), 3)
     self.assertEqual(ix1, ix2)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:6,代码来源:utils_test.py

示例8: testPartialIntersection5

 def testPartialIntersection5(self):
     values, ix1, ix2 = collections.intersect([1, 2, 3], [3, 6])
     self.assertEqual(len(values), 1)
     self.assertEqual(values[0], 3)
     self.assertEqual(ix1[0], 2)
     self.assertEqual(ix2[0], 0)
开发者ID:gansaihua,项目名称:pyalgotrade,代码行数:6,代码来源:utils_test.py


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