1
0

test_multiarray.py 628 B

123456789101112131415161718
  1. from __future__ import division, absolute_import, print_function
  2. import numpy as np
  3. from numpy.testing import assert_, assert_equal, assert_array_equal
  4. class TestView(object):
  5. def test_type(self):
  6. x = np.array([1, 2, 3])
  7. assert_(isinstance(x.view(np.matrix), np.matrix))
  8. def test_keywords(self):
  9. x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)])
  10. # We must be specific about the endianness here:
  11. y = x.view(dtype='<i2', type=np.matrix)
  12. assert_array_equal(y, [[513]])
  13. assert_(isinstance(y, np.matrix))
  14. assert_equal(y.dtype, np.dtype('<i2'))