python类recfromtxt()的实例源码

test_io.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
test_io.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
test_io.py 文件源码 项目:aws-lambda-numpy 作者: vitolimandibhrata 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
genDiskMassProbability.py 文件源码 项目:EM_Bright 作者: shaonghosh 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def fromPostSamp(self, burn=None, skipHeader=12):
        '''
        This method uses lalinference samples. If not burn value is given then the
        entire posterior sample is used. If the burn option is supplied then the
        initial part of the chain (upto iteration number = burn) is ignored.
        Output is a list whose first two elements are the probability that the primary
        and secondary object is a NS respectively. The third element gives the remnant
        mass outside the black hole in access of the threshold mass supplied.
        '''
        data = np.recfromtxt(self.inputFile, names=True, skip_header=skipHeader)
        burnin = 0
        if burn: burnin = burn
        mc = data['mc'][burnin:]
        massRatio = data['q'][burnin:]
        self.chi = data['a1'][burnin:]
        self.eta = massRatio/((1 + massRatio)**2)
        self.mPrimary = (massRatio**(-0.6)) * mc * (1. + massRatio)**0.2
        self.mSecondary = (massRatio**0.4) * mc * (1. + massRatio)**0.2
        NS_prob_2 = np.sum(self.mSecondary < self.max_ns_g_mass)*100./len(self.mSecondary) # RE: Max NS mass was hardcoded as 3.0. Should be gotten from class variable
        NS_prob_1 = np.sum(self.mPrimary < self.max_ns_g_mass)*100./len(self.mPrimary)
        return [NS_prob_1, NS_prob_2, self.computeRemMass()]
test_io.py 文件源码 项目:lambda-numba 作者: rlhotovy 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
test_io.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
test_io.py 文件源码 项目:Alfred 作者: jkachhadia 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(delimiter=",", missing_values="N/A", names=True)
        test = np.recfromtxt(data, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromtxt(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
helper.py 文件源码 项目:CNN_LSTM_CTC_Tensorflow 作者: watsonyanghx 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def load_data(file_to_read):
    """Load X_train/y_train/X_val/y_val/X_infer for further
       processing (e.g. make input queue of tensorflow).

    Args:
        file_to_read:
    Returns:
        X_train/y_train/X_val/y_val/X_infer.
    """

    data = np.recfromtxt(file_to_read)
    data = np.asarray(data)

    return data
swc.py 文件源码 项目:SamuROI 作者: samuroi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __new__(cls, *args,**kwargs):
        # if no argument is given, create zero sized recarray
        if len(args) == 0:
            args = (0,)
        elif type(args[0]) is int:
            # create empty recarray
            d = numpy.recarray(args[0], dtype = SWCFile.swcformat)
        else:
            # create from file or filename
            d = numpy.recfromtxt(args[0], dtype = SWCFile.swcformat)

        return d.view(SWCFile)
zeta.py 文件源码 项目:carsus 作者: tardis-sn 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def ingest_zeta_values(self):
        t_values = np.arange(2000, 42000, 2000)

        names = ['atomic_number', 'ion_charge']
        names += [str(i) for i in t_values]

        zeta = np.recfromtxt(
                self.data_fn,
                usecols=xrange(1, 23),
                names=names)

        zeta_df = (
                pd.DataFrame.from_records(zeta).set_index(
                    ['atomic_number', 'ion_charge']).T
                )

        data = list()
        for i, s in zeta_df.iterrows():
            T = Temperature.as_unique(self.session, value=int(i))
            if T.id is None:
                self.session.flush()

            for (atomic_number, ion_charge), rate in s.iteritems():
                data.append(
                    Zeta(
                            atomic_number=atomic_number,
                            ion_charge=ion_charge,
                            data_source=self.data_source,
                            temp=T,
                            zeta=rate
                            )
                    )
test_io.py 文件源码 项目:deliver 作者: orchestor 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_recfromtxt(self):
        with temppath(suffix='.txt') as path:
            path = Path(path)
            with path.open('w') as f:
                f.write(u'A,B\n0,1\n2,3')

            kwargs = dict(delimiter=",", missing_values="N/A", names=True)
            test = np.recfromtxt(path, **kwargs)
            control = np.array([(0, 1), (2, 3)],
                               dtype=[('A', np.int), ('B', np.int)])
            self.assertTrue(isinstance(test, np.recarray))
            assert_equal(test, control)


问题


面经


文章

微信
公众号

扫码关注公众号