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

Commit 1b87f12

Browse files
committed
fix bug
1 parent 709c956 commit 1b87f12

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

python/mxnet/ndarray/numpy/_op.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,17 @@ def append(arr, values, axis=None):
6969
delete : Delete elements from an array.
7070
Examples
7171
--------
72-
>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
73-
array([1, 2, 3, ..., 7, 8, 9])
72+
>>> np.append(np.array([1, 2, 3]), np.array([[4, 5, 6],[7, 8, 9]]))
73+
array([1., 2., 3., 4., 5., 6., 7., 8., 9.])
7474
When `axis` is specified, `values` must have the correct shape.
75-
>>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
76-
array([[1, 2, 3],
77-
[4, 5, 6],
78-
[7, 8, 9]])
79-
>>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
80-
Traceback (most recent call last):
81-
...
82-
ValueError: all the input arrays must have same number of dimensions
75+
>>> np.append(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[7, 8, 9]]), axis=0)
76+
array([[1., 2., 3.],
77+
[4., 5., 6.],
78+
[7., 8., 9.]])
8379
"""
8480
if axis is None:
85-
arr = arr.ravel()
86-
values = values.ravel()
81+
arr = arr.flatten()
82+
values = values.flatten()
8783
axis = 0
8884
return concatenate((arr, values), axis=axis)
8985

python/mxnet/numpy/multiarray.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6449,21 +6449,17 @@ def append(arr, values, axis=None):
64496449
delete : Delete elements from an array.
64506450
Examples
64516451
--------
6452-
>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
6453-
array([1, 2, 3, ..., 7, 8, 9])
6452+
>>> np.append(np.array([1, 2, 3]), np.array([[4, 5, 6],[7, 8, 9]]))
6453+
array([1., 2., 3., 4., 5., 6., 7., 8., 9.])
64546454
When `axis` is specified, `values` must have the correct shape.
6455-
>>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
6456-
array([[1, 2, 3],
6457-
[4, 5, 6],
6458-
[7, 8, 9]])
6459-
>>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
6460-
Traceback (most recent call last):
6461-
...
6462-
ValueError: all the input arrays must have same number of dimensions
6455+
>>> np.append(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[7, 8, 9]]), axis=0)
6456+
array([[1., 2., 3.],
6457+
[4., 5., 6.],
6458+
[7., 8., 9.]])
64636459
"""
64646460
if axis is None:
6465-
arr = arr.ravel()
6466-
values = values.ravel()
6461+
arr = arr.flatten()
6462+
values = values.flatten()
64676463
axis = 0
64686464
return concatenate((arr, values), axis=axis)
64696465

python/mxnet/symbol/numpy/_symbol.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,21 +4583,17 @@ def append(arr, values, axis=None):
45834583
delete : Delete elements from an array.
45844584
Examples
45854585
--------
4586-
>>> np.append([1, 2, 3], [[4, 5, 6], [7, 8, 9]])
4587-
array([1, 2, 3, ..., 7, 8, 9])
4586+
>>> np.append(np.array([1, 2, 3]), np.array([[4, 5, 6],[7, 8, 9]]))
4587+
array([1., 2., 3., 4., 5., 6., 7., 8., 9.])
45884588
When `axis` is specified, `values` must have the correct shape.
4589-
>>> np.append([[1, 2, 3], [4, 5, 6]], [[7, 8, 9]], axis=0)
4590-
array([[1, 2, 3],
4591-
[4, 5, 6],
4592-
[7, 8, 9]])
4593-
>>> np.append([[1, 2, 3], [4, 5, 6]], [7, 8, 9], axis=0)
4594-
Traceback (most recent call last):
4595-
...
4596-
ValueError: all the input arrays must have same number of dimensions
4589+
>>> np.append(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[7, 8, 9]]), axis=0)
4590+
array([[1., 2., 3.],
4591+
[4., 5., 6.],
4592+
[7., 8., 9.]])
45974593
"""
45984594
if axis is None:
4599-
arr = arr.ravel()
4600-
values = values.ravel()
4595+
arr = arr.flatten()
4596+
values = values.flatten()
46014597
axis = 0
46024598
return concatenate((arr, values), axis=axis)
46034599

tests/python/unittest/test_numpy_op.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,12 +3555,13 @@ def hybrid_forward(self, F, a, b):
35553555

35563556
def get_new_shape(shape, axis):
35573557
shape_lst = list(shape)
3558-
shape_lst[axis] = random.randint(0, 3)
3558+
if axis is not None:
3559+
shape_lst[axis] = random.randint(0, 3)
35593560
return tuple(shape_lst)
35603561

35613562
for shape in [(0, 0), (2, 3)]:
35623563
for hybridize in [True, False]:
3563-
for axis in range(2):
3564+
for axis in [0, 1, None]:
35643565
#test gluon
35653566
test_append = TestAppend(axis=axis)
35663567
if hybridize:

0 commit comments

Comments
 (0)