Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
modify code logic and patterns
Browse files Browse the repository at this point in the history
fix sanity error
  • Loading branch information
JiangZhaoh committed Nov 22, 2019
1 parent 3e9cf37 commit f4a1826
Show file tree
Hide file tree
Showing 4 changed files with 320 additions and 366 deletions.
1 change: 1 addition & 0 deletions python/mxnet/numpy/multiarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7149,6 +7149,7 @@ def insert(arr, obj, values, axis=None):
"""
return _mx_nd_np.insert(arr, obj, values, axis=axis)


@set_module('mxnet.numpy')
def nonzero(a):
"""
Expand Down
51 changes: 4 additions & 47 deletions python/mxnet/symbol/numpy/_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,14 +2493,14 @@ def insert(arr, obj, values, axis=None):
Parameters
----------
arr : ndarray
arr : _Symbol
Input array.
obj : int, slice or ndarray of ints
obj : int, slice or _Symbol of ints
Object that defines the index or indices before which `values` is
inserted.
Support for multiple insertions when `obj` is a single scalar or a
sequence with one element (only support int32 and int64 element).
values : ndarray
values : _Symbol
Values to insert into `arr`.
The type of `values` should equal to the type of `arr`.
`values` should be shaped so that ``arr[...,obj,...] = values``
Expand All @@ -2511,7 +2511,7 @@ def insert(arr, obj, values, axis=None):
Returns
-------
out : ndarray
out : _Symbol
A copy of `arr` with `values` inserted. Note that `insert`
does not occur in-place: a new array is returned. If
`axis` is None, `out` is a flattened array.
Expand All @@ -2521,49 +2521,6 @@ def insert(arr, obj, values, axis=None):
Note that for higher dimensional inserts `obj=0` behaves very different
from `obj=[0]` just like `arr[:,0,:] = values` is different from
`arr[:,[0],:] = values`.
Examples
--------
>>> a = np.array([[1, 1], [2, 2], [3, 3]])
>>> a
array([[1., 1.],
[2., 2.],
[3., 3.]])
>>> np.insert(a, 1, np.array(5))
array([1., 5., 1., 2., 2., 3., 3.])
>>> np.insert(a, 1, np.array(5), axis=1)
array([[1., 5., 1.],
[2., 5., 2.],
[3., 5., 3.]])
Difference between sequence and scalars:
>>> np.insert(a, np.array([1], dtype=np.int32), np.array([[1],[2],[3]]), axis=1)
array([[1., 1., 1.],
[2., 2., 2.],
[3., 3., 3.]])
>>> np.insert(a, 1, np.array([1, 2, 3]), axis=1)
array([[1., 1., 1.],
[2., 2., 2.],
[3., 3., 3.]])
>>> b = a.flatten()
>>> b
array([1., 1., 2., 2., 3., 3.])
>>> np.insert(b, np.array([2, 2], dtype=np.int64), np.array([5, 6]))
array([1., 1., 5., 6., 2., 2., 3., 3.])
>>> np.insert(b, slice(2, 4), np.array([5, 6]))
array([1., 1., 5., 2., 6., 2., 3., 3.])
>>> np.insert(b, np.array([2, 2], dtype=np.int32), np.array([7.13, False]))
array([1. , 1. , 7.13, 0. , 2. , 2. , 3. , 3. ])
>>> x = np.arange(8).reshape(2, 4)
>>> idx = np.array([1, 3], dtype=np.int32)
>>> np.insert(x, idx, np.array([999]), axis=1)
array([[ 0., 999., 1., 2., 999., 3.],
[ 4., 999., 5., 6., 999., 7.]])
"""
if not isinstance(arr, ndarray): # pylint: disable= undefined-variable
raise TypeError("'arr' can not support type {}".format(str(type(arr))))
Expand Down
Loading

0 comments on commit f4a1826

Please sign in to comment.