[Numpy-discussion] Toward release 1.0 of NumPy
Tim Hochberg
tim.hochberg at cox.net
Thu Apr 13 08:44:47 CDT 2006
Alan G Isaac wrote:
>On Thu, 13 Apr 2006, Charles R Harris apparently wrote:
>
>
>>The Kronecker product (aka Tensor product) of two
>>matrices isn't a matrix.
>>
>>
>
>That is an unusual way to describe things in
>the world of econometrics. Here is a more
>common way:
>http://planetmath.org/encyclopedia/KroneckerProduct.html
>I share Sven's expectation.
>
>
mathworld also agrees with you. As does the documentation (as best as I
can tell) and the actual output of kron. I think Charles must be
thinking of the tensor product instead.
In fact, if you look at the code you see this:
# TODO: figure out how to keep arrays the same
I think that in general this is going to be a bit of an issue whenever
we have multiple arguments. Let me propose the world's second dumbest
(in a good way, maybe) procedure:
def kron(a,b):
wrappers = [(getattr(x, '__array_priority__', 0),
x.__array_wrap__) for x in [a,b]
if hasattr(x, '__array_wrap__')]
if wrappers:
priority, wrap = wrappers[-1]
else:
wrap = None
# ....
result = concatenate(concatenate(o, axis=1), axis=1)
if wrap is not None:
result = wrap(result)
return result
This generalizes what _wrapit does for arbitrary arguments. It breaks
'ties' where more than one argument wants to wrap something by using
__array_priority__. You'd actually want to factor out the wrapper
finding code. This generalized what _wrapit does to multiple dimensions.
Thought?
Better plans?
-tim
More information about the Numpy-discussion
mailing list