本文整理汇总了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))
)
示例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)
示例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))
示例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
示例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
示例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'
示例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]
示例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"))
示例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}
示例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')
示例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)
示例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 )
示例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)
示例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'))
示例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)