当前位置: 首页>>代码示例>>Python>>正文


Python numpy.chararray方法代码示例

本文整理汇总了Python中numpy.chararray方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.chararray方法的具体用法?Python numpy.chararray怎么用?Python numpy.chararray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.chararray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: display_policy_grid

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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) 
开发者ID:yrlu,项目名称:reinforcement_learning,代码行数:21,代码来源:gridworld.py

示例2: test_slice

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_defchararray.py

示例3: test_slice

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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')) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:18,代码来源:test_defchararray.py

示例4: min_max_years

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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 
开发者ID:bullocke,项目名称:coded,代码行数:22,代码来源:postprocess_utils.py

示例5: setup

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_defchararray.py

示例6: test_add

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_defchararray.py

示例7: test_radd

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
def test_radd(self):
        QA = np.array([['qabc', 'q123'],
                       ['q789', 'qxyz']]).view(np.chararray)
        assert_array_equal(QA, ('q' + self.A)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_defchararray.py

示例8: test_mul

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:test_defchararray.py

示例9: test_mod

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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]])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_defchararray.py

示例10: test_rmod

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_defchararray.py

示例11: test_empty_indexing

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_defchararray.py

示例12: test_chararray_rstrip

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_regression.py

示例13: get_sequence_strings

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
def get_sequence_strings(encoded_sequences):
  """
    Converts encoded sequences into an array with sequence strings
    """
  num_samples, _, _, seq_length = np.shape(encoded_sequences)
  sequence_characters = np.chararray((num_samples, seq_length))
  sequence_characters[:] = 'N'
  for i, letter in enumerate(['A', 'C', 'G', 'T']):
    letter_indxs = (encoded_sequences[:, :, i, :] == 1).squeeze()
    sequence_characters[letter_indxs] = letter
  # return 1D view of sequence characters
  return sequence_characters.view('S%s' % (seq_length)).ravel() 
开发者ID:deepchem,项目名称:deepchem,代码行数:14,代码来源:utils.py

示例14: setUp

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:7,代码来源:test_defchararray.py

示例15: test_mul

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import chararray [as 别名]
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") 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:17,代码来源:test_defchararray.py


注:本文中的numpy.chararray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。