Python numpy.chararray() Examples
The following are 30
code examples of numpy.chararray().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: gridworld.py From reinforcement_learning with MIT License | 7 votes |
def display_policy_grid(self, policy): """ prints a nice table of the policy in grid input: policy a dictionary of the optimal policy {<state, action_dist>} """ print "==Display policy grid==" policy_grid = np.chararray((len(self.grid), len(self.grid[0]))) for k in self.get_states(): if self.is_terminal((k[0], k[1])) or self.grid[k[0]][k[1]] == 'x': policy_grid[k[0]][k[1]] = '-' else: # policy_grid[k[0]][k[1]] = self.dirs[agent.get_action((k[0], k[1]))] policy_grid[k[0]][k[1]] = self.dirs[policy[(k[0], k[1])][0][0]] row_format = '{:>20}' * (len(self.grid[0])) for row in policy_grid: print row_format.format(*row)
Example #2
Source File: test_defchararray.py From vnpy_crypto with MIT License | 6 votes |
def test_slice(self): """Regression test for https://github.com/numpy/numpy/issues/5982""" arr = np.array([['abc ', 'def '], ['geh ', 'ijk ']], dtype='S4').view(np.chararray) sl1 = arr[:] assert_array_equal(sl1, arr) assert_(sl1.base is arr) assert_(sl1.base.base is arr.base) sl2 = arr[:, :] assert_array_equal(sl2, arr) assert_(sl2.base is arr) assert_(sl2.base.base is arr.base) assert_(arr[0, 0] == b'abc')
Example #3
Source File: test_defchararray.py From recruit with Apache License 2.0 | 6 votes |
def test_slice(self): """Regression test for https://github.com/numpy/numpy/issues/5982""" arr = np.array([['abc ', 'def '], ['geh ', 'ijk ']], dtype='S4').view(np.chararray) sl1 = arr[:] assert_array_equal(sl1, arr) assert_(sl1.base is arr) assert_(sl1.base.base is arr.base) sl2 = arr[:, :] assert_array_equal(sl2, arr) assert_(sl2.base is arr) assert_(sl2.base.base is arr.base) assert_(arr[0, 0] == b'abc')
Example #4
Source File: test_defchararray.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_slice(self): """Regression test for https://github.com/numpy/numpy/issues/5982""" arr = np.array([['abc ', 'def '], ['geh ', 'ijk ']], dtype='S4').view(np.chararray) sl1 = arr[:] assert_array_equal(sl1, arr) assert_(sl1.base is arr) assert_(sl1.base.base is arr.base) sl2 = arr[:, :] assert_array_equal(sl2, arr) assert_(sl2.base is arr) assert_(sl2.base.base is arr.base) assert_(arr[0, 0] == asbytes('abc'))
Example #5
Source File: postprocess_utils.py From coded with MIT License | 6 votes |
def min_max_years(config, image, before): """ Exclude data outside of min and max year desired """ min_year = int(config['postprocessing']['minimum_year']) if not min_year: min_year = 1980 max_year = int(config['postprocessing']['maximum_year']) if not max_year: max_year = 2200 year_image = image[0,:,:].astype(np.str).view(np.chararray).ljust(4) year_image = np.array(year_image).astype(np.float) bad_indices = np.logical_or(year_image < min_year, year_image > max_year) for i in range(image.shape[0] - 1): image[i,:,:][bad_indices] = 0 image[image.shape[0]-1,:,:][bad_indices] = before[bad_indices] return image
Example #6
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_mul(self): A = self.A for r in (2, 3, 5, 7, 197): Ar = np.array([[A[0, 0]*r, A[0, 1]*r], [A[1, 0]*r, A[1, 1]*r]]).view(np.chararray) assert_array_equal(Ar, (self.A * r)) for ob in [object(), 'qrs']: with assert_raises_regex(ValueError, 'Can only multiply by integers'): A*ob
Example #7
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def setup(self): self.A = np.array([['abc', '123'], ['789', 'xyz']]).view(np.chararray) self.B = np.array([['efg', '456'], ['051', 'tuv']]).view(np.chararray)
Example #8
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_rmod(self): assert_(("%s" % self.A) == str(self.A)) assert_(("%r" % self.A) == repr(self.A)) for ob in [42, object()]: with assert_raises_regex( TypeError, "unsupported operand type.* and 'chararray'"): ob % self.A
Example #9
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def setup(self): self.A = np.array([[' abc ', ''], ['12345', 'MixedCase'], ['123 \t 345 \0 ', 'UPPER']], dtype='S').view(np.chararray) self.B = np.array([[u' \u03a3 ', u''], [u'12345', u'MixedCase'], [u'123 \t 345 \0 ', u'UPPER']]).view(np.chararray)
Example #10
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def setup(self): self.A = np.array([['abc', '123'], ['789', 'xyz']]).view(np.chararray) self.B = np.array([['efg', '123 '], ['051', 'tuv']]).view(np.chararray)
Example #11
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def setup(self): TestComparisons.setup(self) self.A = np.array([['abc', '123'], ['789', 'xyz']], np.unicode_).view(np.chararray)
Example #12
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def setup(self): TestComparisons.setup(self) self.B = np.array([['efg', '123 '], ['051', 'tuv']], np.unicode_).view(np.chararray)
Example #13
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_mod(self): """Ticket #856""" F = np.array([['%d', '%f'], ['%s', '%r']]).view(np.chararray) C = np.array([[3, 7], [19, 1]]) FC = np.array([['3', '7.000000'], ['19', '1']]).view(np.chararray) assert_array_equal(FC, F % C) A = np.array([['%.3f', '%d'], ['%s', '%r']]).view(np.chararray) A1 = np.array([['1.000', '1'], ['1', '1']]).view(np.chararray) assert_array_equal(A1, (A % 1)) A2 = np.array([['1.000', '2'], ['3', '4']]).view(np.chararray) assert_array_equal(A2, (A % [[1, 2], [3, 4]]))
Example #14
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def test_add(self): AB = np.array([['abcefg', '123456'], ['789051', 'xyztuv']]).view(np.chararray) assert_array_equal(AB, (self.A + self.B)) assert_(len((self.A + self.B)[0][0]) == 6)
Example #15
Source File: test_defchararray.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_add(self): AB = np.array([['abcefg', '123456'], ['789051', 'xyztuv']]).view(np.chararray) assert_array_equal(AB, (self.A + self.B)) assert_(len((self.A + self.B)[0][0]) == 6)
Example #16
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): self.A = np.array([[' abc ', ''], ['12345', 'MixedCase'], ['123 \t 345 \0 ', 'UPPER']], dtype='S').view(np.chararray) self.B = np.array([[sixu(' \u03a3 '), sixu('')], [sixu('12345'), sixu('MixedCase')], [sixu('123 \t 345 \0 '), sixu('UPPER')]]).view(np.chararray)
Example #17
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): TestComparisons.setUp(self) self.A = np.array([['abc', '123'], ['789', 'xyz']], np.unicode_).view(np.chararray)
Example #18
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): TestComparisons.setUp(self) self.B = np.array([['efg', '123 '], ['051', 'tuv']], np.unicode_).view(np.chararray)
Example #19
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): self.A = np.array([['abc', '123'], ['789', 'xyz']]).view(np.chararray) self.B = np.array([['efg', '123 '], ['051', 'tuv']]).view(np.chararray)
Example #20
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): self.A = np.array('abc1', dtype='c').view(np.chararray)
Example #21
Source File: test_defchararray.py From Computable with MIT License | 5 votes |
def setUp(self): self.A = np.array([['abc ', '123 '], ['789 ', 'xyz ']]).view(np.chararray) self.B = np.array([['abc', '123'], ['789', 'xyz']]).view(np.chararray)
Example #22
Source File: functions.py From picosdk-python-wrappers with ISC License | 5 votes |
def splitMSODataFast(dataLength, data): """ # This implementation will work on either channel in the same way as the splitMSOData method above, albeit in a more efficient manner. Returns a tuple of 8 arrays, each of which is the values over time of a different digital channel. The tuple contains the channels in order (D7, D6, D5, ... D0) or equivalently (D15, D14, D13, ... D8). splitMSODataFast( c_int32 dataLength c_int16 array data ) """ # Makes an array for each digital channel bufferBinaryDj = ( np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), np.chararray(dataLength.value), ) # Splits out the individual bits from the port into the binary values for each digital channel/pin. for i in range(dataLength.value): for j in range(8): bufferBinaryDj[j][i] = 1 if (data[i] & (1 << (7-j))) else 0 return bufferBinaryDj
Example #23
Source File: test_regression.py From vnpy_crypto with MIT License | 5 votes |
def test_chararray_rstrip(self): # Ticket #222 x = np.chararray((1,), 5) x[0] = b'a ' x = x.rstrip() assert_equal(x[0], b'a')
Example #24
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_empty_indexing(): """Regression test for ticket 1948.""" # Check that indexing a chararray with an empty list/array returns an # empty chararray instead of a chararray with a single empty string in it. s = np.chararray((4,)) assert_(s[[]].size == 0)
Example #25
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_rmod(self): assert_(("%s" % self.A) == str(self.A)) assert_(("%r" % self.A) == repr(self.A)) for ob in [42, object()]: try: ob % self.A except TypeError: pass else: self.fail("chararray __rmod__ should fail with " "non-string objects")
Example #26
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_mod(self): """Ticket #856""" F = np.array([['%d', '%f'], ['%s', '%r']]).view(np.chararray) C = np.array([[3, 7], [19, 1]]) FC = np.array([['3', '7.000000'], ['19', '1']]).view(np.chararray) assert_array_equal(FC, F % C) A = np.array([['%.3f', '%d'], ['%s', '%r']]).view(np.chararray) A1 = np.array([['1.000', '1'], ['1', '1']]).view(np.chararray) assert_array_equal(A1, (A % 1)) A2 = np.array([['1.000', '2'], ['3', '4']]).view(np.chararray) assert_array_equal(A2, (A % [[1, 2], [3, 4]]))
Example #27
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_mul(self): A = self.A for r in (2, 3, 5, 7, 197): Ar = np.array([[A[0, 0]*r, A[0, 1]*r], [A[1, 0]*r, A[1, 1]*r]]).view(np.chararray) assert_array_equal(Ar, (self.A * r)) for ob in [object(), 'qrs']: try: A * ob except ValueError: pass else: self.fail("chararray can only be multiplied by integers")
Example #28
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_radd(self): QA = np.array([['qabc', 'q123'], ['q789', 'qxyz']]).view(np.chararray) assert_array_equal(QA, ('q' + self.A))
Example #29
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def test_add(self): AB = np.array([['abcefg', '123456'], ['789051', 'xyztuv']]).view(np.chararray) assert_array_equal(AB, (self.A + self.B)) assert_(len((self.A + self.B)[0][0]) == 6)
Example #30
Source File: test_defchararray.py From vnpy_crypto with MIT License | 5 votes |
def setup(self): self.A = np.array([['abc', '123'], ['789', 'xyz']]).view(np.chararray) self.B = np.array([['efg', '456'], ['051', 'tuv']]).view(np.chararray)