示例#1
0
 def test_nd_to_sa_no_type(self):
     nd = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=float)
     dtype = np.dtype({'names': map('f{}'.format, xrange(3)),
                       'formats': [float] * 3})
     control = np.array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)], dtype=dtype)
     result = utils.cast_np_nd_to_sa(nd)
     self.assertEqual(control.dtype, result.dtype)
     self.assertTrue(np.array_equal(result, control))
示例#2
0
 def test_nd_to_sa_w_type(self):
     nd = np.array([[1, 2, 3], [4, 5, 6]], dtype=int)
     dtype = np.dtype({'names': map('f{}'.format, xrange(3)),
                       'formats': [int] * 3})
     control = np.array([(1, 2, 3), (4, 5, 6)], dtype=dtype)
     result = utils.cast_np_nd_to_sa(nd, dtype)
     self.assertEqual(control.dtype, result.dtype)
     self.assertTrue(np.array_equal(result, control))
示例#3
0
 def test_nd_to_sa_no_type(self):
     nd = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], dtype=float)
     dtype = np.dtype({
         'names': map('f{}'.format, xrange(3)),
         'formats': [float] * 3
     })
     control = np.array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)], dtype=dtype)
     result = utils.cast_np_nd_to_sa(nd)
     self.assertEqual(control.dtype, result.dtype)
     self.assertTrue(np.array_equal(result, control))
示例#4
0
 def test_nd_to_sa_w_type(self):
     nd = np.array([[1, 2, 3], [4, 5, 6]], dtype=int)
     dtype = np.dtype({
         'names': map('f{}'.format, xrange(3)),
         'formats': [int] * 3
     })
     control = np.array([(1, 2, 3), (4, 5, 6)], dtype=dtype)
     result = utils.cast_np_nd_to_sa(nd, dtype)
     self.assertEqual(control.dtype, result.dtype)
     self.assertTrue(np.array_equal(result, control))