8000 ENH: Added an output argument for numpy.outer by svmudkavi · Pull Request #4459 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Added an output argument for numpy.outer #4459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ENH: Added an output argument for numpy.outer
    < 8000 li class="loading">Loading branch information
svmudkavi committed Mar 6, 2014
commit 26f053db9d9cf9b4701dc8f4c48f733338635fa7
6 changes: 4 additions & 2 deletions numpy/core/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ def convolve(a,v,mode='full'):
mode = _mode_from_name(mode)
return multiarray.correlate(a, v[::-1], mode)

def outer(a, b):
def outer(a, b, out=None):
"""
Compute the outer product of two vectors.

Expand All @@ -1012,6 +1012,8 @@ def outer(a, b):
b : (N,) array_like
Second input vector. Input is flattened if
not already 1-dimensional.
out : (M, N) ndarray, optional
A location where the result is stored
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still needs a .. versionadded:: 1.9.0 tag
see e.g. the np.percentile interpolation argument in 1.9 for an example


Returns
-------
Expand Down Expand Up @@ -1065,7 +1067,7 @@ def outer(a, b):
"""
a = asarray(a)
b = asarray(b)
return a.ravel()[:, newaxis]*b.ravel()[newaxis,:]
return multiply(a.ravel()[:, newaxis], b.ravel()[newaxis,:], out)

# try to import blas optimized dot if available
try:
Expand Down
9 changes: 9 additions & 0 deletions numpy/core/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,15 @@ def test_broadcasting(self):
assert_raises(ValueError, np.cross, u, v, axisa=-5, axisb=2)
assert_raises(ValueError, np.cross, u, v, axisa=1, axisb=-4)

def test_outer_out_param():
arr1 = np.ones((5,))
arr2 = np.ones((2,))
arr3 = np.linspace(-2, 2, 5)
out1 = np.ndarray(shape=(5,5))
out2 = np.ndarray(shape=(2, 5))
res1 = np.outer(arr1, arr3, out1)
assert_equal(res1, out1)
assert_equal(np.outer(arr2, arr3, out2), out2)

if __name__ == "__main__":
run_module_suite()
0