Python numpy.AxisError() Examples
The following are 30
code examples of numpy.AxisError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_errors(self): x = np.random.randn(1, 2, 3) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, 3, 0) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, -4, 0) assert_raises_regex(np.AxisError, 'destination.*out of bounds', np.moveaxis, x, 0, 5) assert_raises_regex(ValueError, 'repeated axis in `source`', np.moveaxis, x, [0, 0], [0, 1]) assert_raises_regex(ValueError, 'repeated axis in `destination`', np.moveaxis, x, [0, 1], [1, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, 0, [0, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, [0, 1], [0])
Example #2
Source File: test_core.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_count_func(self): # Tests count assert_equal(1, count(1)) assert_equal(0, array(1, mask=[1])) ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0]) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) ott = ott.reshape((2, 2)) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_equal([1, 2], res) assert_(getmask(res) is nomask) ott = array([0., 1., 2., 3.]) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_(res.dtype.type is np.intp) assert_raises(np.AxisError, ott.count, axis=1)
Example #3
Source File: test_extras.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_axis_argument_errors(self): msg = "mask = %s, ndim = %s, axis = %s, overwrite_input = %s" for ndmin in range(5): for mask in [False, True]: x = array(1, ndmin=ndmin, mask=mask) # Valid axis values should not raise exception args = itertools.product(range(-ndmin, ndmin), [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except Exception: raise AssertionError(msg % (mask, ndmin, axis, over)) # Invalid axis values should raise exception args = itertools.product([-(ndmin + 1), ndmin], [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except np.AxisError: pass else: raise AssertionError(msg % (mask, ndmin, axis, over))
Example #4
Source File: test_core.py From recruit with Apache License 2.0 | 6 votes |
def test_count_func(self): # Tests count assert_equal(1, count(1)) assert_equal(0, array(1, mask=[1])) ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0]) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) ott = ott.reshape((2, 2)) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_equal([1, 2], res) assert_(getmask(res) is nomask) ott = array([0., 1., 2., 3.]) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_(res.dtype.type is np.intp) assert_raises(np.AxisError, ott.count, axis=1)
Example #5
Source File: test_function_base.py From recruit with Apache License 2.0 | 6 votes |
def test_prepend(self): x = np.arange(5) + 1 assert_array_equal(diff(x, prepend=0), np.ones(5)) assert_array_equal(diff(x, prepend=[0]), np.ones(5)) assert_array_equal(np.cumsum(np.diff(x, prepend=0)), x) assert_array_equal(diff(x, prepend=[-1, 0]), np.ones(6)) x = np.arange(4).reshape(2, 2) result = np.diff(x, axis=1, prepend=0) expected = [[0, 1], [2, 1]] assert_array_equal(result, expected) result = np.diff(x, axis=1, prepend=[[0], [0]]) assert_array_equal(result, expected) result = np.diff(x, axis=0, prepend=0) expected = [[0, 1], [2, 2]] assert_array_equal(result, expected) result = np.diff(x, axis=0, prepend=[[0, 0]]) assert_array_equal(result, expected) assert_raises(ValueError, np.diff, x, prepend=np.zeros((3,3))) assert_raises(np.AxisError, diff, x, prepend=0, axis=3)
Example #6
Source File: test_linalg.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_bad_args(self): # Check that bad arguments raise the appropriate exceptions. A = self.array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) B = np.arange(1, 25, dtype=self.dt).reshape(2, 3, 4) # Using `axis=<integer>` or passing in a 1-D array implies vector # norms are being computed, so also using `ord='fro'` # or `ord='nuc'` raises a ValueError. assert_raises(ValueError, norm, A, 'fro', 0) assert_raises(ValueError, norm, A, 'nuc', 0) assert_raises(ValueError, norm, [3, 4], 'fro', None) assert_raises(ValueError, norm, [3, 4], 'nuc', None) # Similarly, norm should raise an exception when ord is any finite # number other than 1, 2, -1 or -2 when computing matrix norms. for order in [0, 3]: assert_raises(ValueError, norm, A, order, None) assert_raises(ValueError, norm, A, order, (0, 1)) assert_raises(ValueError, norm, B, order, (1, 2)) # Invalid axis assert_raises(np.AxisError, norm, B, None, 3) assert_raises(np.AxisError, norm, B, None, (2, 3)) assert_raises(ValueError, norm, B, None, (0, 1, 2))
Example #7
Source File: test_shape_base.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_invalid(self): """ Test it errors when indices has too few dimensions """ a = np.ones((10, 10)) ai = np.ones((10, 2), dtype=np.intp) # sanity check take_along_axis(a, ai, axis=1) # not enough indices assert_raises(ValueError, take_along_axis, a, np.array(1), axis=1) # bool arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(bool), axis=1) # float arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(float), axis=1) # invalid axis assert_raises(np.AxisError, take_along_axis, a, ai, axis=10)
Example #8
Source File: test_extras.py From recruit with Apache License 2.0 | 6 votes |
def test_axis_argument_errors(self): msg = "mask = %s, ndim = %s, axis = %s, overwrite_input = %s" for ndmin in range(5): for mask in [False, True]: x = array(1, ndmin=ndmin, mask=mask) # Valid axis values should not raise exception args = itertools.product(range(-ndmin, ndmin), [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except Exception: raise AssertionError(msg % (mask, ndmin, axis, over)) # Invalid axis values should raise exception args = itertools.product([-(ndmin + 1), ndmin], [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except np.AxisError: pass else: raise AssertionError(msg % (mask, ndmin, axis, over))
Example #9
Source File: test_linalg.py From recruit with Apache License 2.0 | 6 votes |
def test_bad_args(self): # Check that bad arguments raise the appropriate exceptions. A = self.array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) B = np.arange(1, 25, dtype=self.dt).reshape(2, 3, 4) # Using `axis=<integer>` or passing in a 1-D array implies vector # norms are being computed, so also using `ord='fro'` # or `ord='nuc'` raises a ValueError. assert_raises(ValueError, norm, A, 'fro', 0) assert_raises(ValueError, norm, A, 'nuc', 0) assert_raises(ValueError, norm, [3, 4], 'fro', None) assert_raises(ValueError, norm, [3, 4], 'nuc', None) # Similarly, norm should raise an exception when ord is any finite # number other than 1, 2, -1 or -2 when computing matrix norms. for order in [0, 3]: assert_raises(ValueError, norm, A, order, None) assert_raises(ValueError, norm, A, order, (0, 1)) assert_raises(ValueError, norm, B, order, (1, 2)) # Invalid axis assert_raises(np.AxisError, norm, B, None, 3) assert_raises(np.AxisError, norm, B, None, (2, 3)) assert_raises(ValueError, norm, B, None, (0, 1, 2))
Example #10
Source File: test_shape_base.py From recruit with Apache License 2.0 | 6 votes |
def test_invalid(self): """ Test it errors when indices has too few dimensions """ a = np.ones((10, 10)) ai = np.ones((10, 2), dtype=np.intp) # sanity check take_along_axis(a, ai, axis=1) # not enough indices assert_raises(ValueError, take_along_axis, a, np.array(1), axis=1) # bool arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(bool), axis=1) # float arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(float), axis=1) # invalid axis assert_raises(np.AxisError, take_along_axis, a, ai, axis=10)
Example #11
Source File: test_numeric.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_errors(self): x = np.random.randn(1, 2, 3) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, 3, 0) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, -4, 0) assert_raises_regex(np.AxisError, 'destination.*out of bounds', np.moveaxis, x, 0, 5) assert_raises_regex(ValueError, 'repeated axis in `source`', np.moveaxis, x, [0, 0], [0, 1]) assert_raises_regex(ValueError, 'repeated axis in `destination`', np.moveaxis, x, [0, 1], [1, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, 0, [0, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, [0, 1], [0])
Example #12
Source File: test_function_base.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_specific_axes(self): # Testing that gradient can work on a given axis only v = [[1, 1], [3, 4]] x = np.array(v) dx = [np.array([[2., 3.], [2., 3.]]), np.array([[0., 0.], [1., 1.]])] assert_array_equal(gradient(x, axis=0), dx[0]) assert_array_equal(gradient(x, axis=1), dx[1]) assert_array_equal(gradient(x, axis=-1), dx[1]) assert_array_equal(gradient(x, axis=(1, 0)), [dx[1], dx[0]]) # test axis=None which means all axes assert_almost_equal(gradient(x, axis=None), [dx[0], dx[1]]) # and is the same as no axis keyword given assert_almost_equal(gradient(x, axis=None), gradient(x)) # test vararg order assert_array_equal(gradient(x, 2, 3, axis=(1, 0)), [dx[1]/2.0, dx[0]/3.0]) # test maximal number of varargs assert_raises(TypeError, gradient, x, 1, 2, axis=1) assert_raises(np.AxisError, gradient, x, axis=3) assert_raises(np.AxisError, gradient, x, axis=-3) # assert_raises(TypeError, gradient, x, axis=[1,])
Example #13
Source File: test_numeric.py From recruit with Apache License 2.0 | 6 votes |
def test_broadcasting_shapes(self): u = np.ones((2, 1, 3)) v = np.ones((5, 3)) assert_equal(np.cross(u, v).shape, (2, 5, 3)) u = np.ones((10, 3, 5)) v = np.ones((2, 5)) assert_equal(np.cross(u, v, axisa=1, axisb=0).shape, (10, 5, 3)) assert_raises(np.AxisError, np.cross, u, v, axisa=1, axisb=2) assert_raises(np.AxisError, np.cross, u, v, axisa=3, axisb=0) u = np.ones((10, 3, 5, 7)) v = np.ones((5, 7, 2)) assert_equal(np.cross(u, v, axisa=1, axisc=2).shape, (10, 5, 3, 7)) assert_raises(np.AxisError, np.cross, u, v, axisa=-5, axisb=2) assert_raises(np.AxisError, np.cross, u, v, axisa=1, axisb=-4) # gh-5885 u = np.ones((3, 4, 2)) for axisc in range(-2, 2): assert_equal(np.cross(u, u, axisc=axisc).shape, (3, 4))
Example #14
Source File: test_numeric.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_broadcasting_shapes(self): u = np.ones((2, 1, 3)) v = np.ones((5, 3)) assert_equal(np.cross(u, v).shape, (2, 5, 3)) u = np.ones((10, 3, 5)) v = np.ones((2, 5)) assert_equal(np.cross(u, v, axisa=1, axisb=0).shape, (10, 5, 3)) assert_raises(np.AxisError, np.cross, u, v, axisa=1, axisb=2) assert_raises(np.AxisError, np.cross, u, v, axisa=3, axisb=0) u = np.ones((10, 3, 5, 7)) v = np.ones((5, 7, 2)) assert_equal(np.cross(u, v, axisa=1, axisc=2).shape, (10, 5, 3, 7)) assert_raises(np.AxisError, np.cross, u, v, axisa=-5, axisb=2) assert_raises(np.AxisError, np.cross, u, v, axisa=1, axisb=-4) # gh-5885 u = np.ones((3, 4, 2)) for axisc in range(-2, 2): assert_equal(np.cross(u, u, axisc=axisc).shape, (3, 4))
Example #15
Source File: test_linalg.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_bad_args(self): # Check that bad arguments raise the appropriate exceptions. A = self.array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) B = np.arange(1, 25, dtype=self.dt).reshape(2, 3, 4) # Using `axis=<integer>` or passing in a 1-D array implies vector # norms are being computed, so also using `ord='fro'` # or `ord='nuc'` raises a ValueError. assert_raises(ValueError, norm, A, 'fro', 0) assert_raises(ValueError, norm, A, 'nuc', 0) assert_raises(ValueError, norm, [3, 4], 'fro', None) assert_raises(ValueError, norm, [3, 4], 'nuc', None) # Similarly, norm should raise an exception when ord is any finite # number other than 1, 2, -1 or -2 when computing matrix norms. for order in [0, 3]: assert_raises(ValueError, norm, A, order, None) assert_raises(ValueError, norm, A, order, (0, 1)) assert_raises(ValueError, norm, B, order, (1, 2)) # Invalid axis assert_raises(np.AxisError, norm, B, None, 3) assert_raises(np.AxisError, norm, B, None, (2, 3)) assert_raises(ValueError, norm, B, None, (0, 1, 2))
Example #16
Source File: test_extras.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_axis_argument_errors(self): msg = "mask = %s, ndim = %s, axis = %s, overwrite_input = %s" for ndmin in range(5): for mask in [False, True]: x = array(1, ndmin=ndmin, mask=mask) # Valid axis values should not raise exception args = itertools.product(range(-ndmin, ndmin), [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except Exception: raise AssertionError(msg % (mask, ndmin, axis, over)) # Invalid axis values should raise exception args = itertools.product([-(ndmin + 1), ndmin], [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except np.AxisError: pass else: raise AssertionError(msg % (mask, ndmin, axis, over))
Example #17
Source File: test_core.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_count_func(self): # Tests count assert_equal(1, count(1)) assert_equal(0, array(1, mask=[1])) ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0]) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) ott = ott.reshape((2, 2)) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_equal([1, 2], res) assert_(getmask(res) is nomask) ott = array([0., 1., 2., 3.]) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_(res.dtype.type is np.intp) assert_raises(np.AxisError, ott.count, axis=1)
Example #18
Source File: test_shape_base.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_invalid(self): """ Test it errors when indices has too few dimensions """ a = np.ones((10, 10)) ai = np.ones((10, 2), dtype=np.intp) # sanity check take_along_axis(a, ai, axis=1) # not enough indices assert_raises(ValueError, take_along_axis, a, np.array(1), axis=1) # bool arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(bool), axis=1) # float arrays not allowed assert_raises(IndexError, take_along_axis, a, ai.astype(float), axis=1) # invalid axis assert_raises(np.AxisError, take_along_axis, a, ai, axis=10)
Example #19
Source File: test_function_base.py From vnpy_crypto with MIT License | 6 votes |
def test_specific_axes(self): # Testing that gradient can work on a given axis only v = [[1, 1], [3, 4]] x = np.array(v) dx = [np.array([[2., 3.], [2., 3.]]), np.array([[0., 0.], [1., 1.]])] assert_array_equal(gradient(x, axis=0), dx[0]) assert_array_equal(gradient(x, axis=1), dx[1]) assert_array_equal(gradient(x, axis=-1), dx[1]) assert_array_equal(gradient(x, axis=(1, 0)), [dx[1], dx[0]]) # test axis=None which means all axes assert_almost_equal(gradient(x, axis=None), [dx[0], dx[1]]) # and is the same as no axis keyword given assert_almost_equal(gradient(x, axis=None), gradient(x)) # test vararg order assert_array_equal(gradient(x, 2, 3, axis=(1, 0)), [dx[1]/2.0, dx[0]/3.0]) # test maximal number of varargs assert_raises(TypeError, gradient, x, 1, 2, axis=1) assert_raises(np.AxisError, gradient, x, axis=3) assert_raises(np.AxisError, gradient, x, axis=-3) # assert_raises(TypeError, gradient, x, axis=[1,])
Example #20
Source File: test_function_base.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_prepend(self): x = np.arange(5) + 1 assert_array_equal(diff(x, prepend=0), np.ones(5)) assert_array_equal(diff(x, prepend=[0]), np.ones(5)) assert_array_equal(np.cumsum(np.diff(x, prepend=0)), x) assert_array_equal(diff(x, prepend=[-1, 0]), np.ones(6)) x = np.arange(4).reshape(2, 2) result = np.diff(x, axis=1, prepend=0) expected = [[0, 1], [2, 1]] assert_array_equal(result, expected) result = np.diff(x, axis=1, prepend=[[0], [0]]) assert_array_equal(result, expected) result = np.diff(x, axis=0, prepend=0) expected = [[0, 1], [2, 2]] assert_array_equal(result, expected) result = np.diff(x, axis=0, prepend=[[0, 0]]) assert_array_equal(result, expected) assert_raises(ValueError, np.diff, x, prepend=np.zeros((3,3))) assert_raises(np.AxisError, diff, x, prepend=0, axis=3)
Example #21
Source File: test_core.py From vnpy_crypto with MIT License | 6 votes |
def test_count_func(self): # Tests count assert_equal(1, count(1)) assert_equal(0, array(1, mask=[1])) ott = array([0., 1., 2., 3.], mask=[1, 0, 0, 0]) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) ott = ott.reshape((2, 2)) res = count(ott) assert_(res.dtype.type is np.intp) assert_equal(3, res) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_equal([1, 2], res) assert_(getmask(res) is nomask) ott = array([0., 1., 2., 3.]) res = count(ott, 0) assert_(isinstance(res, ndarray)) assert_(res.dtype.type is np.intp) assert_raises(np.AxisError, ott.count, axis=1)
Example #22
Source File: test_extras.py From vnpy_crypto with MIT License | 6 votes |
def test_axis_argument_errors(self): msg = "mask = %s, ndim = %s, axis = %s, overwrite_input = %s" for ndmin in range(5): for mask in [False, True]: x = array(1, ndmin=ndmin, mask=mask) # Valid axis values should not raise exception args = itertools.product(range(-ndmin, ndmin), [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except Exception: raise AssertionError(msg % (mask, ndmin, axis, over)) # Invalid axis values should raise exception args = itertools.product([-(ndmin + 1), ndmin], [False, True]) for axis, over in args: try: np.ma.median(x, axis=axis, overwrite_input=over) except np.AxisError: pass else: raise AssertionError(msg % (mask, ndmin, axis, over))
Example #23
Source File: test_linalg.py From vnpy_crypto with MIT License | 6 votes |
def test_bad_args(self): # Check that bad arguments raise the appropriate exceptions. A = array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) B = np.arange(1, 25, dtype=self.dt).reshape(2, 3, 4) # Using `axis=<integer>` or passing in a 1-D array implies vector # norms are being computed, so also using `ord='fro'` # or `ord='nuc'` raises a ValueError. assert_raises(ValueError, norm, A, 'fro', 0) assert_raises(ValueError, norm, A, 'nuc', 0) assert_raises(ValueError, norm, [3, 4], 'fro', None) assert_raises(ValueError, norm, [3, 4], 'nuc', None) # Similarly, norm should raise an exception when ord is any finite # number other than 1, 2, -1 or -2 when computing matrix norms. for order in [0, 3]: assert_raises(ValueError, norm, A, order, None) assert_raises(ValueError, norm, A, order, (0, 1)) assert_raises(ValueError, norm, B, order, (1, 2)) # Invalid axis assert_raises(np.AxisError, norm, B, None, 3) assert_raises(np.AxisError, norm, B, None, (2, 3)) assert_raises(ValueError, norm, B, None, (0, 1, 2))
Example #24
Source File: test_numeric.py From vnpy_crypto with MIT License | 6 votes |
def test_errors(self): x = np.random.randn(1, 2, 3) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, 3, 0) assert_raises_regex(np.AxisError, 'source.*out of bounds', np.moveaxis, x, -4, 0) assert_raises_regex(np.AxisError, 'destination.*out of bounds', np.moveaxis, x, 0, 5) assert_raises_regex(ValueError, 'repeated axis in `source`', np.moveaxis, x, [0, 0], [0, 1]) assert_raises_regex(ValueError, 'repeated axis in `destination`', np.moveaxis, x, [0, 1], [1, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, 0, [0, 1]) assert_raises_regex(ValueError, 'must have the same number', np.moveaxis, x, [0, 1], [0])
Example #25
Source File: test_function_base.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_extended_axis_invalid(self): d = np.ones((3, 5, 7, 11)) assert_raises(np.AxisError, np.percentile, d, axis=-5, q=25) assert_raises(np.AxisError, np.percentile, d, axis=(0, -5), q=25) assert_raises(np.AxisError, np.percentile, d, axis=4, q=25) assert_raises(np.AxisError, np.percentile, d, axis=(0, 4), q=25) # each of these refers to the same axis twice assert_raises(ValueError, np.percentile, d, axis=(1, 1), q=25) assert_raises(ValueError, np.percentile, d, axis=(-1, -1), q=25) assert_raises(ValueError, np.percentile, d, axis=(3, -1), q=25)
Example #26
Source File: test_function_base.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_multidim(self): a = [[1, 1, 1]] r = [[2, 2, 2], [1, 1, 1]] assert_equal(insert(a, 0, [1]), [1, 1, 1, 1]) assert_equal(insert(a, 0, [2, 2, 2], axis=0), r) assert_equal(insert(a, 0, 2, axis=0), r) assert_equal(insert(a, 2, 2, axis=1), [[1, 1, 2, 1]]) a = np.array([[1, 1], [2, 2], [3, 3]]) b = np.arange(1, 4).repeat(3).reshape(3, 3) c = np.concatenate( (a[:, 0:1], np.arange(1, 4).repeat(3).reshape(3, 3).T, a[:, 1:2]), axis=1) assert_equal(insert(a, [1], [[1], [2], [3]], axis=1), b) assert_equal(insert(a, [1], [1, 2, 3], axis=1), c) # scalars behave differently, in this case exactly opposite: assert_equal(insert(a, 1, [1, 2, 3], axis=1), b) assert_equal(insert(a, 1, [[1], [2], [3]], axis=1), c) a = np.arange(4).reshape(2, 2) assert_equal(insert(a[:, :1], 1, a[:, 1], axis=1), a) assert_equal(insert(a[:1,:], 1, a[1,:], axis=0), a) # negative axis value a = np.arange(24).reshape((2, 3, 4)) assert_equal(insert(a, 1, a[:,:, 3], axis=-1), insert(a, 1, a[:,:, 3], axis=2)) assert_equal(insert(a, 1, a[:, 2,:], axis=-2), insert(a, 1, a[:, 2,:], axis=1)) # invalid axis value assert_raises(np.AxisError, insert, a, 1, a[:, 2, :], axis=3) assert_raises(np.AxisError, insert, a, 1, a[:, 2, :], axis=-4) # negative axis value a = np.arange(24).reshape((2, 3, 4)) assert_equal(insert(a, 1, a[:, :, 3], axis=-1), insert(a, 1, a[:, :, 3], axis=2)) assert_equal(insert(a, 1, a[:, 2, :], axis=-2), insert(a, 1, a[:, 2, :], axis=1))
Example #27
Source File: test_function_base.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extended_axis_invalid(self): d = np.ones((3, 5, 7, 11)) assert_raises(np.AxisError, np.percentile, d, axis=-5, q=25) assert_raises(np.AxisError, np.percentile, d, axis=(0, -5), q=25) assert_raises(np.AxisError, np.percentile, d, axis=4, q=25) assert_raises(np.AxisError, np.percentile, d, axis=(0, 4), q=25) # each of these refers to the same axis twice assert_raises(ValueError, np.percentile, d, axis=(1, 1), q=25) assert_raises(ValueError, np.percentile, d, axis=(-1, -1), q=25) assert_raises(ValueError, np.percentile, d, axis=(3, -1), q=25)
Example #28
Source File: test_arraysetops.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_unique_axis_errors(self): assert_raises(TypeError, self._run_axis_tests, object) assert_raises(TypeError, self._run_axis_tests, [('a', int), ('b', object)]) assert_raises(np.AxisError, unique, np.arange(10), axis=2) assert_raises(np.AxisError, unique, np.arange(10), axis=-2)
Example #29
Source File: test_function_base.py From recruit with Apache License 2.0 | 5 votes |
def test_axes(self): assert_raises(np.AxisError, np.flip, np.ones(4), axis=1) assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=2) assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=-3) assert_raises(np.AxisError, np.flip, np.ones((4, 4)), axis=(0, 3))
Example #30
Source File: test_function_base.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extended_axis_invalid(self): d = np.ones((3, 5, 7, 11)) assert_raises(np.AxisError, np.median, d, axis=-5) assert_raises(np.AxisError, np.median, d, axis=(0, -5)) assert_raises(np.AxisError, np.median, d, axis=4) assert_raises(np.AxisError, np.median, d, axis=(0, 4)) assert_raises(ValueError, np.median, d, axis=(1, 1))