MCPcopy Create free account
hub / github.com/numpy/numpy / test_prepend

Method test_prepend

numpy/lib/tests/test_function_base.py:799–821  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

797 assert_(type(out3) is type(x))
798
799 def test_prepend(self):
800 x = np.arange(5) + 1
801 assert_array_equal(diff(x, prepend=0), np.ones(5))
802 assert_array_equal(diff(x, prepend=[0]), np.ones(5))
803 assert_array_equal(np.cumsum(np.diff(x, prepend=0)), x)
804 assert_array_equal(diff(x, prepend=[-1, 0]), np.ones(6))
805
806 x = np.arange(4).reshape(2, 2)
807 result = np.diff(x, axis=1, prepend=0)
808 expected = [[0, 1], [2, 1]]
809 assert_array_equal(result, expected)
810 result = np.diff(x, axis=1, prepend=[[0], [0]])
811 assert_array_equal(result, expected)
812
813 result = np.diff(x, axis=0, prepend=0)
814 expected = [[0, 1], [2, 2]]
815 assert_array_equal(result, expected)
816 result = np.diff(x, axis=0, prepend=[[0, 0]])
817 assert_array_equal(result, expected)
818
819 assert_raises(ValueError, np.diff, x, prepend=np.zeros((3,3)))
820
821 assert_raises(np.AxisError, diff, x, prepend=0, axis=3)
822
823 def test_append(self):
824 x = np.arange(5)

Callers

nothing calls this directly

Calls 5

assert_array_equalFunction · 0.90
diffFunction · 0.90
assert_raisesFunction · 0.90
cumsumMethod · 0.80
reshapeMethod · 0.80

Tested by

no test coverage detected