You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/10/23 07:01:10 UTC

[GitHub] [incubator-mxnet] hgt312 commented on a change in pull request #16564: [numpy] add numpy operator : append

hgt312 commented on a change in pull request #16564: [numpy] add numpy operator : append
URL: https://github.com/apache/incubator-mxnet/pull/16564#discussion_r337877040
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -6419,3 +6419,47 @@ def einsum(*operands, **kwargs):
     ...     np.einsum('ijk,ilm,njm,nlk,abc->',a,a,a,a,a, optimize=True)
     """
     return _mx_nd_np.einsum(*operands, **kwargs)
+
+
+@set_module('mxnet.numpy')
+def append(arr, values, axis=None):
+    """
+    Append values to the end of an array.
+    Parameters
+    ----------
+    arr : ndarray
+        Values are appended to a copy of this array.
+    values : ndarray
+        These values are appended to a copy of `arr`.  It must be of the
+        correct shape (the same shape as `arr`, excluding `axis`).  If
+        `axis` is not specified, `values` can be any shape and will be
+        flattened before use.
+    axis : int, optional
+        The axis along which `values` are appended.  If `axis` is not
+        given, both `arr` and `values` are flattened before use.
+    Returns
+    -------
+    append : ndarray
+        A copy of `arr` with `values` appended to `axis`.  Note that
+        `append` does not occur in-place: a new array is allocated and
+        filled.  If `axis` is None, `out` is a flattened array.
+    See Also
+    --------
+    insert : Insert elements into an array.
+    delete : Delete elements from an array.
+    Examples
+    --------
+    >>> np.append(np.array([1, 2, 3]), np.array([[4, 5, 6],[7, 8, 9]]))
+    array([1., 2., 3., 4., 5., 6., 7., 8., 9.])
+    When `axis` is specified, `values` must have the correct shape.
+    >>> np.append(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[7, 8, 9]]), axis=0)
+    array([[1., 2., 3.],
+           [4., 5., 6.],
+           [7., 8., 9.]])
+    """
+    if axis is None:
+        arr = arr.flatten()
+        values = values.flatten()
+        axis = 0
+    return concatenate((arr, values), axis=axis)
 
 Review comment:
   Do not return `concat` here, it makes the function in `_op` unused
   ```suggestion
       return _mx_nd_np.append(...)
   ```
   Besides, argument `axis` in `append` and `concat` has the same effect, just pass the ndarrays is OK, no need to flatten.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services