Name
outer
Synopsis
u.outer(a,b)Returns an array r whose shape tuple is
a
.shape+
b
.shape.
For each tuple ta indexing
a and tb
indexing b,
a
[
ta
],
operated (with the function or operator underlying
u) with
b
[
tb
],
is put in
r
[
ta
+
tb
]
(the + here indicates tuple concatenation). The
overall operation is known in mathematics as the outer product when
u is multiply. For
example:
a = Numeric.arange(3, 5)
b = Numeric.arange(1, 6)
c = Numeric.multiply.outer(a, b)
print a.shape, b.shape, c.shape # prints: (2,) (5,) (2,5)
print c # prints: [[3 6 9 12 15]
# [4 8 12 16 20]]
c
.shape is
(2,5), the concatenation of the shape tuples of
operands a and
b. Each i row
of c is the whole of
b multiplied by the corresponding
i element of a.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access