本文整理汇总了Python中numpy.unicode_函数的典型用法代码示例。如果您正苦于以下问题:Python unicode_函数的具体用法?Python unicode_怎么用?Python unicode_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unicode_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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ÿ')
示例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)
示例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)
示例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)
示例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)
示例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")
示例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_)
示例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)
示例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
示例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)
示例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)
示例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')
示例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
示例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')