test_multiarray.py 554 B

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