當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.str_方法代碼示例

本文整理匯總了Python中numpy.str_方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.str_方法的具體用法?Python numpy.str_怎麽用?Python numpy.str_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.str_方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_to_waterfall_bl_multi_pol

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_to_waterfall_bl_multi_pol():
    uvf = UVFlag(test_f_file)
    uvf.weights_array = np.ones_like(uvf.weights_array)
    uvf2 = uvf.copy()
    uvf2.polarization_array[0] = -4
    uvf.__add__(uvf2, inplace=True, axis="pol")  # Concatenate to form multi-pol object
    uvf2 = uvf.copy()  # Keep a copy to run with keep_pol=False
    uvf.to_waterfall()
    assert uvf.type == "waterfall"
    assert uvf.metric_array.shape == (
        len(uvf.time_array),
        len(uvf.freq_array),
        len(uvf.polarization_array),
    )
    assert uvf.weights_array.shape == uvf.metric_array.shape
    assert len(uvf.polarization_array) == 2
    # Repeat with keep_pol=False
    uvf2.to_waterfall(keep_pol=False)
    assert uvf2.type == "waterfall"
    assert uvf2.metric_array.shape == (len(uvf2.time_array), len(uvf.freq_array), 1)
    assert uvf2.weights_array.shape == uvf2.metric_array.shape
    assert len(uvf2.polarization_array) == 1
    assert uvf2.polarization_array[0] == np.str_(
        ",".join(map(str, uvf.polarization_array))
    ) 
開發者ID:RadioAstronomySoftwareGroup,項目名稱:pyuvdata,代碼行數:27,代碼來源:test_uvflag.py

示例2: store_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def store_data(self, store_loc, **kwargs):
    """Put arrays to store
        """
    #print(store_loc)
    g = self.store.create_group(store_loc)
    for k, v, in kwargs.items():
      #print(type(v[0]))

      #print(k)
      if type(v) == list:
        if len(v) != 0:
          if type(v[0]) is np.str_ or type(v[0]) is str:
            v = [a.encode('utf8') for a in v]

      g.create_dataset(
          k, data=v, compression=self.clib, compression_opts=self.clev) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:18,代碼來源:pyanitools.py

示例3: test_scalar_none_comparison

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_scalar_none_comparison(self):
        # Scalars should still just return False and not give a warnings.
        # The comparisons are flagged by pep8, ignore that.
        with warnings.catch_warnings(record=True) as w:
            warnings.filterwarnings('always', '', FutureWarning)
            assert_(not np.float32(1) == None)
            assert_(not np.str_('test') == None)
            # This is dubious (see below):
            assert_(not np.datetime64('NaT') == None)

            assert_(np.float32(1) != None)
            assert_(np.str_('test') != None)
            # This is dubious (see below):
            assert_(np.datetime64('NaT') != None)
        assert_(len(w) == 0)

        # For documentation purposes, this is why the datetime is dubious.
        # At the time of deprecation this was no behaviour change, but
        # it has to be considered when the deprecations are done.
        assert_(np.equal(np.datetime64('NaT'), None)) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:22,代碼來源:test_deprecations.py

示例4: test_collapse_pol_or

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_collapse_pol_or():
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    assert uvf.weights_array is None
    uvf2 = uvf.copy()
    uvf2.polarization_array[0] = -4
    uvf.__add__(uvf2, inplace=True, axis="pol")  # Concatenate to form multi-pol object
    uvf2 = uvf.copy()
    uvf2.collapse_pol(method="or")
    assert len(uvf2.polarization_array) == 1
    assert uvf2.polarization_array[0] == np.str_(
        ",".join(map(str, uvf.polarization_array))
    )
    assert uvf2.mode == "flag"
    assert hasattr(uvf2, "flag_array")
    assert hasattr(uvf2, "metric_array")
    assert uvf2.metric_array is None 
開發者ID:RadioAstronomySoftwareGroup,項目名稱:pyuvdata,代碼行數:19,代碼來源:test_uvflag.py

示例5: test_collapse_pol_flag

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_collapse_pol_flag():
    uvf = UVFlag(test_f_file)
    uvf.to_flag()
    assert uvf.weights_array is None
    uvf2 = uvf.copy()
    uvf2.polarization_array[0] = -4
    uvf.__add__(uvf2, inplace=True, axis="pol")  # Concatenate to form multi-pol object
    uvf2 = uvf.copy()
    uvf2.collapse_pol()
    assert len(uvf2.polarization_array) == 1
    assert uvf2.polarization_array[0] == np.str_(
        ",".join(map(str, uvf.polarization_array))
    )
    assert uvf2.mode == "metric"
    assert hasattr(uvf2, "metric_array")
    assert hasattr(uvf2, "flag_array")
    assert uvf2.flag_array is None 
開發者ID:RadioAstronomySoftwareGroup,項目名稱:pyuvdata,代碼行數:19,代碼來源:test_uvflag.py

示例6: test_fasta_based_dataset

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_fasta_based_dataset(intervals_file, fasta_file):
    # just test the functionality
    dl = StringSeqIntervalDl(intervals_file, fasta_file)
    ret_val = dl[0]
    assert isinstance(ret_val["inputs"], np.ndarray)
    assert ret_val["inputs"].shape == ()
    # # test with set wrong seqlen:
    # dl = StringSeqIntervalDl(intervals_file, fasta_file, required_seq_len=3)
    # with pytest.raises(Exception):
    #     dl[0]

    dl = StringSeqIntervalDl(intervals_file, fasta_file, label_dtype="str")
    ret_val = dl[0]
    assert isinstance(ret_val['targets'][0], np.str_)
    dl = StringSeqIntervalDl(intervals_file, fasta_file, label_dtype="int")
    ret_val = dl[0]
    assert isinstance(ret_val['targets'][0], np.int_)
    dl = StringSeqIntervalDl(intervals_file, fasta_file, label_dtype="bool")
    ret_val = dl[0]
    assert isinstance(ret_val['targets'][0], np.bool_)
    vals = dl.load_all()
    assert vals['inputs'][0] == 'GT' 
開發者ID:kipoi,項目名稱:kipoiseq,代碼行數:24,代碼來源:test_sequence.py

示例7: get_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def get_data(lst,preproc):
   data = []
   result = []
   for path in lst:
       f = dicom.read_file(path)
       img = preproc(f.pixel_array.astype(float) / np.max(f.pixel_array))
       dst_path = path.rsplit(".", 1)[0] + ".64x64.jpg"
       scipy.misc.imsave(dst_path, img)
       result.append(dst_path)
       data.append(img)
   data = np.array(data, dtype=np.uint8)
   data = data.reshape(data.size)
   data = np.array(data, dtype=np.str_)
   data = data.reshape(data.size)
   return [data,result] 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:17,代碼來源:Preprocessing.py

示例8: test_is_instance

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_is_instance(self, core_type_lib):
        assert PushInt.is_instance(5)
        assert PushInt.is_instance(np.int64(100))
        assert not PushInt.is_instance("Foo")
        assert not PushInt.is_instance(np.str_("Bar"))

        assert not PushStr.is_instance(5)
        assert not PushStr.is_instance(np.int64(100))
        assert PushStr.is_instance("Foo")
        assert PushStr.is_instance(np.str_("Bar")) 
開發者ID:erp12,項目名稱:pyshgp,代碼行數:12,代碼來源:test_types.py

示例9: isdecoded

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def isdecoded(self, obj):
        return obj.dtype.type in {np.str_, np.object_, np.datetime64} 
開發者ID:NCAR,項目名稱:esmlab,代碼行數:4,代碼來源:core.py

示例10: test_0d_arrays

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_0d_arrays(self):
        unicode = type(u'')

        assert_equal(unicode(np.array(u'café', '<U4')), u'café')

        if sys.version_info[0] >= 3:
            assert_equal(repr(np.array('café', '<U4')),
                         "array('café', dtype='<U4')")
        else:
            assert_equal(repr(np.array(u'café', '<U4')),
                         "array(u'caf\\xe9', dtype='<U4')")
        assert_equal(str(np.array('test', np.str_)), 'test')

        a = np.zeros(1, dtype=[('a', '<i4', (3,))])
        assert_equal(str(a[0]), '([0, 0, 0],)')

        assert_equal(repr(np.datetime64('2005-02-25')[...]),
                     "array('2005-02-25', dtype='datetime64[D]')")

        assert_equal(repr(np.timedelta64('10', 'Y')[...]),
                     "array(10, dtype='timedelta64[Y]')")

        # repr of 0d arrays is affected by printoptions
        x = np.array(1)
        np.set_printoptions(formatter={'all':lambda x: "test"})
        assert_equal(repr(x), "array(test)")
        # str is unaffected
        assert_equal(str(x), "1")

        # check `style` arg raises
        assert_warns(DeprecationWarning, np.array2string,
                                         np.array(1.), style=repr)
        # but not in legacy mode
        np.array2string(np.array(1.), style=repr, legacy='1.13')
        # gh-10934 style was broken in legacy mode, check it works
        np.array2string(np.array(1.), legacy='1.13') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:38,代碼來源:test_arrayprint.py

示例11: test_object_array_to_fixed_string

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_object_array_to_fixed_string(self):
        # Ticket #1235.
        a = np.array(['abcdefgh', 'ijklmnop'], dtype=np.object_)
        b = np.array(a, dtype=(np.str_, 8))
        assert_equal(a, b)
        c = np.array(a, dtype=(np.str_, 5))
        assert_equal(c, np.array(['abcde', 'ijklm']))
        d = np.array(a, dtype=(np.str_, 12))
        assert_equal(a, d)
        e = np.empty((2, ), dtype=(np.str_, 8))
        e[:] = a[:]
        assert_equal(a, e) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_regression.py

示例12: test_scalar_comparison_to_none

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_scalar_comparison_to_none(self):
        # Scalars should just return False and not give a warnings.
        # The comparisons are flagged by pep8, ignore that.
        with warnings.catch_warnings(record=True) as w:
            warnings.filterwarnings('always', '', FutureWarning)
            assert_(not np.float32(1) == None)
            assert_(not np.str_('test') == None)
            # This is dubious (see below):
            assert_(not np.datetime64('NaT') == None)

            assert_(np.float32(1) != None)
            assert_(np.str_('test') != None)
            # This is dubious (see below):
            assert_(np.datetime64('NaT') != None)
        assert_(len(w) == 0)

        # For documentation purposes, this is why the datetime is dubious.
        # At the time of deprecation this was no behaviour change, but
        # it has to be considered when the deprecations are done.
        assert_(np.equal(np.datetime64('NaT'), None))


#class TestRepr(object):
#    def test_repr(self):
#        for t in types:
#            val = t(1197346475.0137341)
#            val_repr = repr(val)
#            val2 = eval(val_repr)
#            assert_equal( val, val2 ) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:31,代碼來源:test_scalarmath.py

示例13: test_constructor_empty_with_string_dtype

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_constructor_empty_with_string_dtype(self):
        # GH 9428
        expected = DataFrame(index=[0, 1], columns=[0, 1], dtype=object)

        df = DataFrame(index=[0, 1], columns=[0, 1], dtype=str)
        tm.assert_frame_equal(df, expected)
        df = DataFrame(index=[0, 1], columns=[0, 1], dtype=np.str_)
        tm.assert_frame_equal(df, expected)
        df = DataFrame(index=[0, 1], columns=[0, 1], dtype=np.unicode_)
        tm.assert_frame_equal(df, expected)
        df = DataFrame(index=[0, 1], columns=[0, 1], dtype='U5')
        tm.assert_frame_equal(df, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_constructors.py

示例14: test_is_scalar_numpy_array_scalars

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def test_is_scalar_numpy_array_scalars(self):
        assert is_scalar(np.int64(1))
        assert is_scalar(np.float64(1.))
        assert is_scalar(np.int32(1))
        assert is_scalar(np.object_('foobar'))
        assert is_scalar(np.str_('foobar'))
        assert is_scalar(np.unicode_(u('foobar')))
        assert is_scalar(np.bytes_(b'foobar'))
        assert is_scalar(np.datetime64('2014-01-01'))
        assert is_scalar(np.timedelta64(1, 'h')) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_inference.py

示例15: rands_array

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import str_ [as 別名]
def rands_array(nchars, size, dtype='O'):
    """Generate an array of byte strings."""
    retval = (np.random.choice(RANDS_CHARS, size=nchars * np.prod(size))
              .view((np.str_, nchars)).reshape(size))
    if dtype is None:
        return retval
    else:
        return retval.astype(dtype) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:testing.py


注:本文中的numpy.str_方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。