本文整理匯總了Python中distarray.local.localarray.LocalArray.astype方法的典型用法代碼示例。如果您正苦於以下問題:Python LocalArray.astype方法的具體用法?Python LocalArray.astype怎麽用?Python LocalArray.astype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類distarray.local.localarray.LocalArray
的用法示例。
在下文中一共展示了LocalArray.astype方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestArrayConversion
# 需要導入模塊: from distarray.local.localarray import LocalArray [as 別名]
# 或者: from distarray.local.localarray.LocalArray import astype [as 別名]
class TestArrayConversion(MpiTestCase):
""" Test array conversion methods. """
def setUp(self):
# On Python3, an 'int' gets converted to 'np.int64' on copy,
# so we force the numpy type to start with so we get back
# the same thing.
self.int_type = np.int64
self.distribution = Distribution.from_shape(comm=self.comm,
shape=(4,))
self.int_larr = LocalArray(self.distribution, dtype=self.int_type)
self.int_larr.fill(3)
def test_astype(self):
""" Test that astype() works as expected. """
# Convert int array to float.
float_larr = self.int_larr.astype(float)
for global_inds, value in ndenumerate(float_larr):
self.assertEqual(value, 3.0)
self.assertTrue(isinstance(value, float))
# No type specification for a copy.
# Should get same type as we started with.
int_larr2 = self.int_larr.astype(None)
for global_inds, value in ndenumerate(int_larr2):
self.assertEqual(value, 3)
self.assertTrue(isinstance(value, self.int_type))
示例2: test_astype_cbc
# 需要導入模塊: from distarray.local.localarray import LocalArray [as 別名]
# 或者: from distarray.local.localarray.LocalArray import astype [as 別名]
def test_astype_cbc(self):
new_dtype = np.int8
d = Distribution(comm=self.comm, dim_data=self.ddpr[self.comm.Get_rank()])
a = LocalArray(d, dtype=np.int32)
a.fill(12)
b = a.astype(new_dtype)
assert_localarrays_allclose(a, b, check_dtype=False)
self.assertEqual(b.dtype, new_dtype)
self.assertEqual(b.ndarray.dtype, new_dtype)
示例3: test_astype_bn
# 需要導入模塊: from distarray.local.localarray import LocalArray [as 別名]
# 或者: from distarray.local.localarray.LocalArray import astype [as 別名]
def test_astype_bn(self):
new_dtype = np.float32
d = Distribution.from_shape((16, 16), dist=('b', 'n'), comm=self.comm)
a = LocalArray(d, dtype=np.int_)
a.fill(11)
b = a.astype(new_dtype)
assert_localarrays_allclose(a, b, check_dtype=False)
self.assertEqual(b.dtype, new_dtype)
self.assertEqual(b.ndarray.dtype, new_dtype)