diff options
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/arraysetops.py | 7 | ||||
-rw-r--r-- | numpy/lib/stride_tricks.py | 6 | ||||
-rw-r--r-- | numpy/lib/tests/test_stride_tricks.py | 10 |
3 files changed, 17 insertions, 6 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index cb24eb24e..7776d7e76 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -97,10 +97,11 @@ def unique(ar, return_index=False, return_inverse=False, return_counts=False): """ Find the unique elements of an array. - Returns the sorted unique elements of an array. There are two optional + Returns the sorted unique elements of an array. There are three optional outputs in addition to the unique elements: the indices of the input array - that give the unique values, and the indices of the unique array that - reconstruct the input array. + that give the unique values, the indices of the unique array that + reconstruct the input array, and the number of times each unique value + comes up in the input array. Parameters ---------- diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py index 0f46ed335..a5f247abf 100644 --- a/numpy/lib/stride_tricks.py +++ b/numpy/lib/stride_tricks.py @@ -60,9 +60,9 @@ def _broadcast_to(array, shape, subok, readonly): if any(size < 0 for size in shape): raise ValueError('all elements of broadcast shape must be non-' 'negative') - broadcast = np.nditer((array,), flags=['multi_index', 'zerosize_ok'], - op_flags=['readonly'], itershape=shape, order='C' - ).itviews[0] + broadcast = np.nditer( + (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'], + op_flags=['readonly'], itershape=shape, order='C').itviews[0] result = _maybe_view_as_subclass(array, broadcast) if not readonly and array.flags.writeable: result.flags.writeable = True diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py index 0b73109bc..ef483921c 100644 --- a/numpy/lib/tests/test_stride_tricks.py +++ b/numpy/lib/tests/test_stride_tricks.py @@ -364,5 +364,15 @@ def test_writeable(): assert_equal(result.flags.writeable, False) +def test_reference_types(): + input_array = np.array('a', dtype=object) + expected = np.array(['a'] * 3, dtype=object) + actual = broadcast_to(input_array, (3,)) + assert_array_equal(expected, actual) + + actual, _ = broadcast_arrays(input_array, np.ones(3)) + assert_array_equal(expected, actual) + + if __name__ == "__main__": run_module_suite() |