Having just re-read the PEP I'm concerned that this proposal leaves at least
one major (?) trap for naive users, namely
x = np.array([1, 10])
print X.T@x
which will print 101, not [[1, 10], [10, 100]]
Yes, I know why this is happening but it's still a problem -- the user said,
"I'm thinking matrices" when they wrote @ but the x.T had done the "wrong"
thing before the @ kicked in. And yes, a savvy user would have written x =
np.ones([[1, 10]]) (but then np.dot(x, x.T) isn't a scalar).
This is the way things are at present, but with the new @ syntax coming in I
think we should consider fixing it.
I can think of three possibilities:
1. Leave this as a trap for the unwary, and a reason for people to
stick to np.matrix (np.matrix([1, 10]) behaves "correctly")
2. Make x.T a syntax error for 1-D arrays. It's a no-op and IMHO a
trap.
3. Make x.T promote the shape == (2,) array to (1, 2) and return a (2,
1) array. This may be too magic, but it's my preferred solution.
R
> Implementation of @ (matrix multiplication)
> - will be in 3.5 ~ 18months
> - no work started yet -- have to make sure we do it.
> - @@ was not added.
> - The PEP for numpy is well-defined. Not much thinking to be done. (Good for
> a sprint)
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
