本文整理汇总了Python中numpy.unicode_函数的典型用法代码示例。如果您正苦于以下问题:Python unicode_函数的具体用法?Python unicode_怎么用?Python unicode_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unicode_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_numpy_scalar_argument_return_unicode_1
def check_numpy_scalar_argument_return_unicode_1(self):
f = PyCFunction('foo')
f += Variable('a1', numpy.unicode_, 'in, out')
f += Variable('a2', numpy.unicode0, 'in, out')
foo = f.build()
args = (u'hey', [1,2])
results = (numpy.unicode_('hey'), numpy.unicode_('[1, 2]'))
assert_equal(foo(*args), results)
开发者ID:dagss,项目名称:f2py-g3,代码行数:8,代码来源:test_py_support.py
示例2: test_unicode_repr
def test_unicode_repr(self):
from numpy import unicode_
u = unicode_(3)
assert str(u) == '3'
assert repr(u) == "u'3'"
u = unicode_(u'Aÿ')
# raises(UnicodeEncodeError, "str(u)") # XXX
assert repr(u) == repr(u'Aÿ')
开发者ID:abhinavthomas,项目名称:pypy,代码行数:8,代码来源:test_scalar.py
示例3: trainFileHandler
def trainFileHandler():
train_file = raw_input("Enter the file path with Train Data -> ")
#train_file = "NOUN_trn.csv"
print('Loading train data...')
with open(train_file, 'r') as csvfile:
tr = [row for row in reader(csvfile, delimiter='\t')]
train = []
target = []
for i in range(np.shape(tr)[0]):
train.append(np.unicode_(unicode(tr[i][0], encoding='latin2')))
target.append(np.unicode_(unicode(tr[i][1], encoding='latin2')))
return (train, target)
开发者ID:eugeniashurko,项目名称:polish-stem,代码行数:12,代码来源:polishstem.py
示例4: test_numpy_str_someunicode_to_uint16_back
def test_numpy_str_someunicode_to_uint16_back():
for i in range(100):
data = np.unicode_(str_unicode)
intermed = utils.convert_numpy_str_to_uint16(data)
out = utils.convert_to_numpy_str(intermed)[0]
assert out.tostring() == data.tostring()
assert_equal(out, data)
开发者ID:sungjinlees,项目名称:hdf5storage,代码行数:7,代码来源:test_str_conv_utils.py
示例5: test_numpy_str_ascii_to_uint16_back
def test_numpy_str_ascii_to_uint16_back():
for i in range(100):
data = np.unicode_(str_ascii)
intermed = utils.convert_numpy_str_to_uint16(data)
out = utils.convert_to_numpy_str(intermed)[0]
assert_equal_nose(out.tostring(), data.tostring())
assert_equal(out, data)
开发者ID:frejanordsiek,项目名称:hdf5storage,代码行数:7,代码来源:test_str_conv_utils.py
示例6: _convert_list
def _convert_list(self, value):
"""Convert a string into a typed numpy array.
If it is not possible it returns a numpy string.
"""
try:
numpy_values = []
values = value.split(" ")
types = set([])
for string_value in values:
v = self._convert_scalar_value(string_value)
numpy_values.append(v)
types.add(v.dtype.type)
result_type = numpy.result_type(*types)
if issubclass(result_type.type, (numpy.string_, six.binary_type)):
# use the raw data to create the result
return numpy.string_(value)
elif issubclass(result_type.type, (numpy.unicode_, six.text_type)):
# use the raw data to create the result
return numpy.unicode_(value)
else:
return numpy.array(numpy_values, dtype=result_type)
except ValueError:
return numpy.string_(value)
开发者ID:vallsv,项目名称:silx,代码行数:26,代码来源:fabioh5.py
示例7: test_string
def test_string(self):
self.assert_equal_with_lambda_check(_flexible_type("a"), "a")
if sys.version_info.major == 2:
self.assert_equal_with_lambda_check(_flexible_type(unicode("a")), "a")
# numpy types
self.assert_equal_with_lambda_check(_flexible_type(np.string_("a")), "a")
self.assert_equal_with_lambda_check(_flexible_type(np.unicode_("a")), "a")
开发者ID:FLMao,项目名称:SFrame,代码行数:7,代码来源:test_flexible_type.py
示例8: _tobuffer
def _tobuffer(self, object_):
# This works (and is used) only with UCS-4 builds of Python,
# where the width of the internal representation of a
# character matches that of the base atoms.
if not isinstance(object_, str):
raise TypeError("object is not a string: %r" % (object_,))
return numpy.unicode_(object_)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:7,代码来源:atom.py
示例9: test_char_repeat
def test_char_repeat(self):
np_s = np.string_('abc')
np_u = np.unicode_('abc')
np_i = np.int(5)
res_np = np_s * np_i
res_s = b'abc' * 5
assert_(res_np == res_s)
开发者ID:AlerzDev,项目名称:Brazo-Proyecto-Final,代码行数:7,代码来源:test_scalarinherit.py
示例10: get_stellar_variability
def get_stellar_variability(self):
"""
Getter for the change in magnitudes due to stellar
variability. The PhotometryStars mixin is clever enough
to automatically add this to the baseline magnitude.
"""
varParams = self.column_by_name('varParamStr')
output = numpy.empty((6,len(varParams)))
for ii, vv in enumerate(varParams):
if vv != numpy.unicode_("None") and \
self.obs_metadata is not None and \
self.obs_metadata.mjd is not None:
deltaMag = self.applyVariability(vv)
output[0][ii] = deltaMag['u']
output[1][ii] = deltaMag['g']
output[2][ii] = deltaMag['r']
output[3][ii] = deltaMag['i']
output[4][ii] = deltaMag['z']
output[5][ii] = deltaMag['y']
else:
output[0][ii] = 0.0
output[1][ii] = 0.0
output[2][ii] = 0.0
output[3][ii] = 0.0
output[4][ii] = 0.0
output[5][ii] = 0.0
return output
开发者ID:jonathansick-shadow,项目名称:sims_catUtils,代码行数:33,代码来源:VariabilityMixin.py
示例11: test_numpy
def test_numpy(self):
"""NumPy objects get serialized to readable JSON."""
l = [
np.float32(12.5),
np.float64(2.0),
np.float16(0.5),
np.bool(True),
np.bool(False),
np.bool_(True),
np.unicode_("hello"),
np.byte(12),
np.short(12),
np.intc(-13),
np.int_(0),
np.longlong(100),
np.intp(7),
np.ubyte(12),
np.ushort(12),
np.uintc(13),
np.ulonglong(100),
np.uintp(7),
np.int8(1),
np.int16(3),
np.int32(4),
np.int64(5),
np.uint8(1),
np.uint16(3),
np.uint32(4),
np.uint64(5),
]
l2 = [l, np.array([1, 2, 3])]
roundtripped = loads(dumps(l2, cls=EliotJSONEncoder))
self.assertEqual([l, [1, 2, 3]], roundtripped)
开发者ID:ClusterHQ,项目名称:eliot,代码行数:33,代码来源:test_json.py
示例12: test_index_0d_numpy_string
def test_index_0d_numpy_string(self):
# regression test to verify our work around for indexing 0d strings
v = Variable([], np.string_('asdf'))
self.assertVariableIdentical(v[()], v)
v = Variable([], np.unicode_(u'asdf'))
self.assertVariableIdentical(v[()], v)
开发者ID:joonro,项目名称:xarray,代码行数:7,代码来源:test_variable.py
示例13: check_numpy_scalar_argument_return_unicode_2
def check_numpy_scalar_argument_return_unicode_2(self):
f = PyCFunction('foo')
f += Variable('a', 'npy_unicode', 'in, out')
f += 'a.data[0] = \'H\';'
foo = f.build()
s = numpy.unicode_('hey')
assert_equal(foo(s),u'Hey')
assert_equal(s, u'hey')
开发者ID:dagss,项目名称:f2py-g3,代码行数:8,代码来源:test_py_support.py
示例14: testFileHandler
def testFileHandler():
test_file = raw_input("Enter the file path with Test Data -> ")
print('Loading test data...')
with open(test_file, 'r') as csvfile:
test = [row for row in reader(csvfile, delimiter='\t')]
for i in range(np.shape(test)[0]):
test[i] = np.unicode_(unicode(test[i][0], encoding='latin2'))
return test
开发者ID:eugeniashurko,项目名称:polish-stem,代码行数:8,代码来源:polishstem.py
示例15: setUp
def setUp(self):
pass
self.b_lit = b'bytes literal'
self.s_lit = 'literal literal'
self.u_lit = u'unicode literal'
self.np_b_lit = np.bytes_('numpy bytes literal')
self.np_s_lit = np.str_('numpy unicode literal')
self.np_u_lit = np.unicode_('numpy unicode literal')
开发者ID:titusjan,项目名称:argos,代码行数:9,代码来源:test_utils.py
示例16: _tobuffer
def _tobuffer(self, object_):
# This works (and is used) only with UCS-4 builds of Python,
# where the width of the internal representation of a
# character matches that of the base atoms.
if isinstance(object_, bytes):
warnings.warn("Storing bytestrings in VLUnicodeAtom is "
"deprecated.", DeprecationWarning)
elif not isinstance(object_, six.text_type):
raise TypeError("object is not a string: %r" % (object_,))
return numpy.unicode_(object_)
开发者ID:tomkooij,项目名称:PyTables,代码行数:10,代码来源:atom.py
示例17: test_isscalar_numpy_array_scalars
def test_isscalar_numpy_array_scalars(self):
self.assertTrue(lib.isscalar(np.int64(1)))
self.assertTrue(lib.isscalar(np.float64(1.0)))
self.assertTrue(lib.isscalar(np.int32(1)))
self.assertTrue(lib.isscalar(np.object_("foobar")))
self.assertTrue(lib.isscalar(np.str_("foobar")))
self.assertTrue(lib.isscalar(np.unicode_(u("foobar"))))
self.assertTrue(lib.isscalar(np.bytes_(b"foobar")))
self.assertTrue(lib.isscalar(np.datetime64("2014-01-01")))
self.assertTrue(lib.isscalar(np.timedelta64(1, "h")))
开发者ID:Feyi1,项目名称:pandas,代码行数:10,代码来源:test_infer_and_convert.py
示例18: test_isscalar_numpy_array_scalars
def test_isscalar_numpy_array_scalars(self):
self.assertTrue(is_scalar(np.int64(1)))
self.assertTrue(is_scalar(np.float64(1.)))
self.assertTrue(is_scalar(np.int32(1)))
self.assertTrue(is_scalar(np.object_('foobar')))
self.assertTrue(is_scalar(np.str_('foobar')))
self.assertTrue(is_scalar(np.unicode_(u('foobar'))))
self.assertTrue(is_scalar(np.bytes_(b'foobar')))
self.assertTrue(is_scalar(np.datetime64('2014-01-01')))
self.assertTrue(is_scalar(np.timedelta64(1, 'h')))
开发者ID:cgrin,项目名称:pandas,代码行数:10,代码来源:test_inference.py
示例19: random_numpy
def random_numpy(shape, dtype, allow_nan=True,
allow_unicode=False):
# Makes a random numpy array of the specified shape and dtype
# string. The method is slightly different depending on the
# type. For 'bytes', 'str', and 'object'; an array of the
# specified size is made and then each element is set to either
# a numpy.bytes_, numpy.str_, or some other object of any type
# (here, it is a randomly typed random numpy array). If it is
# any other type, then it is just a matter of constructing the
# right sized ndarray from a random sequence of bytes (all must
# be forced to 0 and 1 for bool). Optionally include unicode
# characters.
if dtype == 'S':
length = random.randint(1, max_string_length)
data = np.zeros(shape=shape, dtype='S' + str(length))
for x in np.nditer(data, op_flags=['readwrite']):
if allow_unicode:
chars = random_bytes_fullrange(length)
else:
chars = random_bytes(length)
x[...] = np.bytes_(chars)
return data
elif dtype == 'U':
length = random.randint(1, max_string_length)
data = np.zeros(shape=shape, dtype='U' + str(length))
for x in np.nditer(data, op_flags=['readwrite']):
if allow_unicode:
chars = _random_str_some_unicode(length)
else:
chars = random_str_ascii(length)
x[...] = np.unicode_(chars)
return data
elif dtype == 'object':
data = np.zeros(shape=shape, dtype='object')
for index, x in np.ndenumerate(data):
data[index] = random_numpy( \
shape=random_numpy_shape( \
object_subarray_dimensions, \
max_object_subarray_axis_length), \
dtype=random.choice(dtypes))
return data
else:
nbytes = np.ndarray(shape=(1,), dtype=dtype).nbytes
bts = np.random.bytes(nbytes * np.prod(shape))
if dtype == 'bool':
bts = b''.join([{True: b'\x01', False: b'\x00'}[ \
ch > 127] for ch in bts])
data = np.ndarray(shape=shape, dtype=dtype, buffer=bts)
# If it is a floating point type and we are supposed to
# remove NaN's, then turn them to zeros.
if not allow_nan and data.dtype.kind in ('f', 'c') \
and np.any(np.isnan(data)):
data = data.copy()
data[np.isnan(data)] = 0.0
return data
开发者ID:dashesy,项目名称:hdf5storage,代码行数:55,代码来源:make_randoms.py
示例20: random_numpy_scalar
def random_numpy_scalar(dtype):
# How a random scalar is made depends on th type. For must, it
# is just a single number. But for the string types, it is a
# string of any length.
if dtype == 'S':
return np.bytes_(random_bytes(random.randint(1,
max_string_length)))
elif dtype == 'U':
return np.unicode_(random_str_ascii(
random.randint(1,
max_string_length)))
else:
return random_numpy(tuple(), dtype)[()]
开发者ID:dashesy,项目名称:hdf5storage,代码行数:13,代码来源:make_randoms.py
注:本文中的numpy.unicode_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论