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

Python recfunctions.join_by函数代码示例

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

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



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

示例1: filter_effects

    def filter_effects(self):
        """
        Merge effects and data, and flip effect alleles 
        """
        effect_positions=self.effects[["CHR", "POS"]]
        data_positions=self.data.snp[["CHR", "POS"]]

        effect_include=np.in1d(effect_positions, data_positions)
        data_include=np.in1d(data_positions, effect_positions)

        self.data.filter_snps(data_include)
        self.effects=self.effects[effect_include]
        # Just give up and convert to float. I have no idea why int doesn't work here
        # but it's something to do with the fact that you can't have None as a numpy int
        # wheras float gets converted to nan. 
        tmp_data=nprec.append_fields(self.data.snp, "GENO", None, dtypes=[(float,self.data.geno.shape[1])],usemask=False)
        tmp_data["GENO"]=self.data.geno
        self.effects=nprec.join_by(["CHR", "POS"], self.effects, tmp_data, usemask=False, jointype="inner")
        flipped=0
        removed=0
        for rec in self.effects:
            if rec["EFFECT"]==rec["REF"] and rec["OTHER"]==rec["ALT"]:
                pass
            elif rec["OTHER"]==rec["REF"] and rec["EFFECT"]==rec["ALT"]:
                flipped+=1
                rec["OTHER"]=rec["ALT"]
                rec["EFFECT"]=rec["REF"]
                rec["BETA"]=-rec["BETA"]
            else:
                removed+=1
                rec["EFFECT"]=rec["OTHER"]="N"

        self.effects=self.effects[self.effects["EFFECT"]!="N"]
        print( "Removed "+str(removed)+" non-matching alleles",file=sys.stderr)
        print( "Flipped "+str(flipped)+" alleles",file=sys.stderr)
开发者ID:mathii,项目名称:spindrift,代码行数:35,代码来源:predictor.py


示例2: test_leftouter_join

    def test_leftouter_join(self):
        a, b = self.a, self.b

        test = join_by(("a", "b"), a, b, "leftouter")
        control = ma.array(
            [
                (0, 50, 100, -1),
                (1, 51, 101, -1),
                (2, 52, 102, -1),
                (3, 53, 103, -1),
                (4, 54, 104, -1),
                (5, 55, 105, -1),
                (6, 56, 106, -1),
                (7, 57, 107, -1),
                (8, 58, 108, -1),
                (9, 59, 109, -1),
            ],
            mask=[
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
                (0, 0, 0, 1),
            ],
            dtype=[("a", int), ("b", int), ("c", int), ("d", int)],
        )
        assert_equal(test, control)
开发者ID:haadkhan,项目名称:cerebri,代码行数:32,代码来源:test_recfunctions.py


示例3: merge_cort

def merge_cort(data, cortisol_filename):
    
    cort_data = np.genfromtxt(cortisol_filename, dtype=None, names=True, delimiter='\t')
    
    names = list(cort_data.dtype.names)
    
    # Find all the columns in cort_data that have 'av' in their title
    # and not '_mask'
    drop_names = names[8:]

    cort_data = nprf.drop_fields(cort_data, drop_names, usemask=False, asrecarray=True)
    
    data = nprf.join_by('SubID', data, cort_data, jointype='leftouter',
                            r1postfix='KW', r2postfix='KW2', usemask=False,asrecarray=True)
    
    # Bizzarely, the join_by function pads with the biggest numbers it can think of!
    # So we're going to replace everything over 999 with 999
    for name in names[1:8]:
        data[name][data[name]>999] = 999
    
    # Define a UsableCort field: 1 if ANY of the cortisol values are not 999
    cort_array = np.vstack( [ data[name] for name in names[1:8]])
    usable_cort_array = np.ones(cort_array.shape[1])
    usable_cort_array[np.any(cort_array<>999, axis=0)] = 1
    
    data = nprf.append_fields(base = data, names='UsableCort', data = usable_cort_array, usemask=False)

    return data
开发者ID:KirstieJane,项目名称:MRIMPACT_CODE,代码行数:28,代码来源:RandomiseSetup.py


示例4: test_two_keys_two_vars

    def test_two_keys_two_vars(self):
        a = np.array(
            list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2), np.arange(50, 60), np.arange(10, 20))),
            dtype=[("k", int), ("a", int), ("b", int), ("c", int)],
        )

        b = np.array(
            list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2), np.arange(65, 75), np.arange(0, 10))),
            dtype=[("k", int), ("a", int), ("b", int), ("c", int)],
        )

        control = np.array(
            [
                (10, 0, 50, 65, 10, 0),
                (11, 0, 51, 66, 11, 1),
                (10, 1, 52, 67, 12, 2),
                (11, 1, 53, 68, 13, 3),
                (10, 2, 54, 69, 14, 4),
                (11, 2, 55, 70, 15, 5),
                (10, 3, 56, 71, 16, 6),
                (11, 3, 57, 72, 17, 7),
                (10, 4, 58, 73, 18, 8),
                (11, 4, 59, 74, 19, 9),
            ],
            dtype=[("k", int), ("a", int), ("b1", int), ("b2", int), ("c1", int), ("c2", int)],
        )
        test = join_by(["a", "k"], a, b, r1postfix="1", r2postfix="2", jointype="inner")
        assert_equal(test.dtype, control.dtype)
        assert_equal(test, control)
开发者ID:haadkhan,项目名称:cerebri,代码行数:29,代码来源:test_recfunctions.py


示例5: GetTileDefs

def GetTileDefs(args, strtype='|S12'):
    #t = esutil.io.read(args.tiles)[args.tilecol][0:2]
    t = esutil.io.read(args.tiles)[args.tilecol]
    tindex = np.arange(len(t))
    tiles = np.empty(len(t), dtype=[('tilename',strtype), ('index', np.int64)])
    tiles['tilename'] = t.astype(strtype)
    tiles['index'] = np.arange(len(t))

    if args.density is not None:
        for tile in tiles['tilename']:
            outdir = os.path.join(args.outdir, tile)
            if not os.path.exists(outdir):
                os.makedirs(outdir)

    cur = desdb.connect()
    q = "select urall, uraur, udecll, udecur, tilename from coaddtile order by udecll desc, urall asc"
    arr = cur.quick(q, array=True)

    dt = arr.dtype.descr
    dt[-1] = ('tilename',strtype)
    dt = np.dtype(dt)
    newarr = np.empty(len(arr), dtype=dt)
    for i in range(len(arr.dtype.names)):
        name = arr.dtype.names[i]
        if i == 4:
            newarr[name] = arr[name].astype(strtype)
        else:
            newarr[name] = arr[name]

    tiles = rec.join_by('tilename', newarr, tiles, usemask=False)
    tiles = np.sort(tiles, order='index')
    return tiles
开发者ID:suchyta1,项目名称:Valarauko,代码行数:32,代码来源:BuildPos.py


示例6: test_different_field_order

 def test_different_field_order(self):
     # gh-8940
     a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')])
     b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')])
     # this should not give a FutureWarning:
     j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False)
     assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
开发者ID:vbasu,项目名称:numpy,代码行数:7,代码来源:test_recfunctions.py


示例7: test_outer_join

    def test_outer_join(self):
        a, b = self.a, self.b

        test = join_by(('a', 'b'), a, b, 'outer')
        control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
                            (2, 52, 102, -1), (3, 53, 103, -1),
                            (4, 54, 104, -1), (5, 55, 105, -1),
                            (5, 65, -1, 100), (6, 56, 106, -1),
                            (6, 66, -1, 101), (7, 57, 107, -1),
                            (7, 67, -1, 102), (8, 58, 108, -1),
                            (8, 68, -1, 103), (9, 59, 109, -1),
                            (9, 69, -1, 104), (10, 70, -1, 105),
                            (11, 71, -1, 106), (12, 72, -1, 107),
                            (13, 73, -1, 108), (14, 74, -1, 109)],
                           mask=[(0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 1, 0), (0, 0, 0, 1),
                                 (0, 0, 1, 0), (0, 0, 0, 1),
                                 (0, 0, 1, 0), (0, 0, 0, 1),
                                 (0, 0, 1, 0), (0, 0, 0, 1),
                                 (0, 0, 1, 0), (0, 0, 1, 0),
                                 (0, 0, 1, 0), (0, 0, 1, 0),
                                 (0, 0, 1, 0), (0, 0, 1, 0)],
                           dtype=[('a', int), ('b', int),
                                  ('c', int), ('d', int)])
        assert_equal(test, control)
开发者ID:vbasu,项目名称:numpy,代码行数:27,代码来源:test_recfunctions.py


示例8: test_join_subdtype

 def test_join_subdtype(self):
     # tests the bug in https://stackoverflow.com/q/44769632/102441
     from numpy.lib import recfunctions as rfn
     foo = np.array([(1,)],
                    dtype=[('key', int)])
     bar = np.array([(1, np.array([1,2,3]))],
                    dtype=[('key', int), ('value', 'uint16', 3)])
     res = join_by('key', foo, bar)
     assert_equal(res, bar.view(ma.MaskedArray))
开发者ID:vbasu,项目名称:numpy,代码行数:9,代码来源:test_recfunctions.py


示例9: test_join

    def test_join(self):
        a, b = self.a, self.b

        # Fixme, this test is broken
        # test = join_by(('a', 'b'), a, b)
        # control = np.array([(5, 55, 105, 100), (6, 56, 106, 101),
        #                    (7, 57, 107, 102), (8, 58, 108, 103),
        #                    (9, 59, 109, 104)],
        #                   dtype=[('a', int), ('b', int),
        #                          ('c', int), ('d', int)])
        # assert_equal(test, control)

        # Hack to avoid pyflakes unused variable warnings
        join_by(("a", "b"), a, b)
        np.array(
            [(5, 55, 105, 100), (6, 56, 106, 101), (7, 57, 107, 102), (8, 58, 108, 103), (9, 59, 109, 104)],
            dtype=[("a", int), ("b", int), ("c", int), ("d", int)],
        )
开发者ID:haadkhan,项目名称:cerebri,代码行数:18,代码来源:test_recfunctions.py


示例10: test_inner_join

    def test_inner_join(self):
        # Basic test of join_by
        a, b = self.a, self.b

        test = join_by('a', a, b, jointype='inner')
        control = np.array([(5, 55, 65, 105, 100), (6, 56, 66, 106, 101),
                            (7, 57, 67, 107, 102), (8, 58, 68, 108, 103),
                            (9, 59, 69, 109, 104)],
                           dtype=[('a', int), ('b1', int), ('b2', int),
                                  ('c', int), ('d', int)])
        assert_equal(test, control)
开发者ID:vbasu,项目名称:numpy,代码行数:11,代码来源:test_recfunctions.py


示例11: test_same_name_different_dtypes_key

    def test_same_name_different_dtypes_key(self):
        a_dtype = np.dtype([('key', 'S5'), ('value', '<f4')])
        b_dtype = np.dtype([('key', 'S10'), ('value', '<f4')])
        expected_dtype = np.dtype([
            ('key', 'S10'), ('value1', '<f4'), ('value2', '<f4')])

        a = np.array([('Sarah',  8.0), ('John', 6.0)], dtype=a_dtype)
        b = np.array([('Sarah', 10.0), ('John', 7.0)], dtype=b_dtype)
        res = join_by('key', a, b)

        assert_equal(res.dtype, expected_dtype)
开发者ID:vbasu,项目名称:numpy,代码行数:11,代码来源:test_recfunctions.py


示例12: augment_effects

    def augment_effects(self):
        """
        Add the population frequency information to the effects. 
        """

        tmp_snp=nprec.append_fields(self.data.snp, "FREQ", None, 
                                    dtypes=[(float,self.data.freq.shape[1])],
                                    usemask=False)
        tmp_snp["FREQ"]=self.data.freq
        
        new_effects=nprec.join_by(["CHR", "POS"], self.effects, tmp_snp,
                                  usemask=False, jointype="inner")
        self.effects=new_effects
开发者ID:mathii,项目名称:spindrift,代码行数:13,代码来源:Qx_test.py


示例13: test_subarray_key

    def test_subarray_key(self):
        a_dtype = np.dtype([('pos', int, 3), ('f', '<f4')])
        a = np.array([([1, 1, 1], np.pi), ([1, 2, 3], 0.0)], dtype=a_dtype)

        b_dtype = np.dtype([('pos', int, 3), ('g', '<f4')])
        b = np.array([([1, 1, 1], 3), ([3, 2, 1], 0.0)], dtype=b_dtype)

        expected_dtype = np.dtype([('pos', int, 3), ('f', '<f4'), ('g', '<f4')])
        expected = np.array([([1, 1, 1], np.pi, 3)], dtype=expected_dtype)

        res = join_by('pos', a, b)
        assert_equal(res.dtype, expected_dtype)
        assert_equal(res, expected)
开发者ID:vbasu,项目名称:numpy,代码行数:13,代码来源:test_recfunctions.py


示例14: test_no_r2postfix

    def test_no_r2postfix(self):
        # Basic test of join_by no_r2postfix
        a, b = self.a, self.b

        test = join_by(
            'a', a, b, r1postfix='1', r2postfix='', jointype='inner')
        control = np.array([(0, 50, 65, 100, 100), (1, 51, 66, 101, 101),
                            (2, 52, 67, 102, 102), (3, 53, 68, 103, 103),
                            (4, 54, 69, 104, 104), (5, 55, 70, 105, 105),
                            (6, 56, 71, 106, 106), (7, 57, 72, 107, 107),
                            (8, 58, 73, 108, 108), (9, 59, 74, 109, 109)],
                           dtype=[('a', int), ('b1', int), ('b', int),
                                  ('c', int), ('d', int)])
        assert_equal(test, control)
开发者ID:vbasu,项目名称:numpy,代码行数:14,代码来源:test_recfunctions.py


示例15: join_by

	def join_by(self, r2, key, jointype='inner', r1postfix='1', r2postfix='2',
                defaults=None, asrecarray=False, asTable=True):
		"""
		Join arrays `r1` and `r2` on key `key`.

		The key should be either a string or a sequence of string corresponding
		to the fields used to join the array.
		An exception is raised if the `key` field cannot be found in the two input
		arrays.
		Neither `r1` nor `r2` should have any duplicates along `key`: the presence
		of duplicates will make the output quite unreliable. Note that duplicates
		are not looked for by the algorithm.

		INPUTS:
			key 	   {str, seq} 	A string or a sequence of strings
						corresponding to the fields used for comparison.
			r2 	   [Table]	Table to join with

		KEYWORDS:
			jointype   [str]	{'inner', 'outer', 'leftouter'}
			    'inner'     : returns the elements common to both r1 and r2.
			    'outer'     : returns the common elements as well as the elements
					  of r1 not in r2 and the elements of not in r2.
			    'leftouter' : returns the common elements and the elements of r1 not in r2.

			r1postfix  [str]	String appended to the names of the fields of r1 that are present in r2
			r2postfix  [str] 	String appended to the names of the fields of r2 that are present in r1
			defaults   [dict]	Dictionary mapping field names to the corresponding default values.
			asrecarray [bool] 	Whether to return a recarray or just a flexible-type ndarray.
			asTable	   [bool] 	Whether to return a Table (default).

		*Notes*:
		- The output is sorted along the key.
		- A temporary array is formed by dropping the fields not in the key for the
		  two arrays and concatenating the result. This array is then sorted, and
		  the common entries selected. The output is constructed by filling the fields
		  with the selected entries. Matching is not preserved if there are some
		  duplicates...

		"""
		#TODO: return a Table by default
		if asTable:
			asrecarray = True
		arr = recfunctions.join_by(key, self, r2, jointype=jointype,
				r1postfix=r1postfix, r2postfix=r2postfix,
				defaults=defaults, usemask=False,
				asrecarray=asrecarray)

		return arr
开发者ID:ryanmaas,项目名称:eztables,代码行数:49,代码来源:table.py


示例16: test_padded_dtype

    def test_padded_dtype(self):
        dt = np.dtype('i1,f4', align=True)
        dt.names = ('k', 'v')
        assert_(len(dt.descr), 3)  # padding field is inserted

        a = np.array([(1, 3), (3, 2)], dt)
        b = np.array([(1, 1), (2, 2)], dt)
        res = join_by('k', a, b)

        # no padding fields remain
        expected_dtype = np.dtype([
            ('k', 'i1'), ('v1', 'f4'), ('v2', 'f4')
        ])

        assert_equal(res.dtype, expected_dtype)
开发者ID:vbasu,项目名称:numpy,代码行数:15,代码来源:test_recfunctions.py


示例17: build_utc_array

def build_utc_array(source, sink, start, end):

    source_prices = retrieve_node_data(source, start, end)
    sink_prices = retrieve_node_data(sink, start, end)

    source_data = []

    for element in source_prices:
        source_data.append((element[0].replace(tzinfo=pytz.timezone('EST')),
                            element[1],
                            element[2],
                            element[5]))

    sink_data = []

    for element in sink_prices:
        sink_data.append((element[0].replace(tzinfo=pytz.timezone('EST')),
                          element[1],
                          element[2],
                          element[5]))

    sink_dt = numpy.dtype([('time_id', 'S32'),
                      ('sink_node_id', 'i8'),
                      ('sink_rt_lmp', 'f8'),
                      ('sink_da_lmp', 'f8')])

    source_dt = numpy.dtype([('time_id', 'S32'),
                      ('source_node_id', 'i8'),
                      ('source_rt_lmp', 'f8'),
                      ('source_da_lmp', 'f8')])


    sink_array = numpy.array(sink_data, dtype=sink_dt)
    source_array = numpy.array(source_data, dtype=source_dt)

    joined = rfn.join_by('time_id', sink_array,
                                    source_array,
                                    jointype='inner', usemask=False)

    rt_congestion_rounded = numpy.round(joined['sink_rt_lmp'] - joined['source_rt_lmp'], 2)
    da_congestion_rounded = numpy.round(joined['sink_da_lmp'] - joined['source_da_lmp'], 2)
    profit_rounded = numpy.round(rt_congestion_rounded - da_congestion_rounded, 2)

    joined = rfn.append_fields(joined, 'rt_congestion', data=rt_congestion_rounded)
    joined = rfn.append_fields(joined, 'da_congestion', data=da_congestion_rounded)
    joined = rfn.append_fields(joined, 'profit', data=profit_rounded)

    return joined[['time_id', 'rt_congestion']]
开发者ID:GeStanley,项目名称:comp652_project,代码行数:48,代码来源:interface.py


示例18: test_leftouter_join

    def test_leftouter_join(self):
        a, b = self.a, self.b

        test = join_by(('a', 'b'), a, b, 'leftouter')
        control = ma.array([(0, 50, 100, -1), (1, 51, 101, -1),
                            (2, 52, 102, -1), (3, 53, 103, -1),
                            (4, 54, 104, -1), (5, 55, 105, -1),
                            (6, 56, 106, -1), (7, 57, 107, -1),
                            (8, 58, 108, -1), (9, 59, 109, -1)],
                           mask=[(0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1),
                                 (0, 0, 0, 1), (0, 0, 0, 1)],
                           dtype=[('a', int), ('b', int), ('c', int), ('d', int)])
        assert_equal(test, control)
开发者ID:vbasu,项目名称:numpy,代码行数:16,代码来源:test_recfunctions.py


示例19: test_inner_join

    def test_inner_join(self):
        # Basic test of join_by
        a, b = self.a, self.b

        test = join_by("a", a, b, jointype="inner")
        control = np.array(
            [
                (5, 55, 65, 105, 100),
                (6, 56, 66, 106, 101),
                (7, 57, 67, 107, 102),
                (8, 58, 68, 108, 103),
                (9, 59, 69, 109, 104),
            ],
            dtype=[("a", int), ("b1", int), ("b2", int), ("c", int), ("d", int)],
        )
        assert_equal(test, control)
开发者ID:haadkhan,项目名称:cerebri,代码行数:16,代码来源:test_recfunctions.py


示例20: test_two_keys_two_vars

    def test_two_keys_two_vars(self):
        a = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2),
                              np.arange(50, 60), np.arange(10, 20))),
                     dtype=[('k', int), ('a', int), ('b', int), ('c', int)])

        b = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2),
                              np.arange(65, 75), np.arange(0, 10))),
                     dtype=[('k', int), ('a', int), ('b', int), ('c', int)])

        control = np.array([(10, 0, 50, 65, 10, 0), (11, 0, 51, 66, 11, 1),
                            (10, 1, 52, 67, 12, 2), (11, 1, 53, 68, 13, 3),
                            (10, 2, 54, 69, 14, 4), (11, 2, 55, 70, 15, 5),
                            (10, 3, 56, 71, 16, 6), (11, 3, 57, 72, 17, 7),
                            (10, 4, 58, 73, 18, 8), (11, 4, 59, 74, 19, 9)],
                           dtype=[('k', int), ('a', int), ('b1', int),
                                  ('b2', int), ('c1', int), ('c2', int)])
        test = join_by(
            ['a', 'k'], a, b, r1postfix='1', r2postfix='2', jointype='inner')
        assert_equal(test.dtype, control.dtype)
        assert_equal(test, control)
开发者ID:vbasu,项目名称:numpy,代码行数:20,代码来源:test_recfunctions.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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