Greg Wilson's latest.
This commit is contained in:
parent
4003d90c2d
commit
4a75be97f2
73
pep-0211.txt
73
pep-0211.txt
|
@ -20,7 +20,7 @@ Introduction
|
|||
definitive historical record.
|
||||
|
||||
|
||||
Proposal
|
||||
Summary
|
||||
|
||||
Add a single new infix binary operator '@' ("across"), and
|
||||
corresponding special methods "__across__()", "__racross__()", and
|
||||
|
@ -141,38 +141,12 @@ Proposal
|
|||
|
||||
A new operator '@' (pronounced "across") will be added to Python,
|
||||
along with special methods "__across__()", "__racross__()", and
|
||||
"__iacross__()", with the usual semantics.
|
||||
|
||||
NumPy will overload "@" to perform mathematical multiplication of
|
||||
arrays where shapes permit, and to throw an exception otherwise.
|
||||
Its implementation of "@" will treat built-in sequence types as if
|
||||
they were column vectors. This takes care of the cases MM and MV.
|
||||
|
||||
An attribute "T" will be added to the NumPy array type, such that
|
||||
"m.T" is:
|
||||
|
||||
(a) the transpose of "m" for a 2-dimensional array
|
||||
|
||||
(b) the 1xN matrix transpose of "m" if "m" is a 1-dimensional
|
||||
array; or
|
||||
|
||||
(c) a runtime error for an array with rank >= 3.
|
||||
|
||||
This attribute will alias the memory of the base object. NumPy's
|
||||
"transpose()" function will be extended to turn built-in sequence
|
||||
types into row vectors. This takes care of the VM, VD, and VO
|
||||
cases. We propose an attribute because:
|
||||
|
||||
(a) the resulting notation is similar to the 'superscript T' (at
|
||||
least, as similar as ASCII allows), and
|
||||
|
||||
(b) it signals that the transposition aliases the original object.
|
||||
"__iacross__()", with the usual semantics. (We recommend using
|
||||
"@", rather than the times-like "><", because of the ease with
|
||||
which the latter could be mis-typed as inequality "<>".)
|
||||
|
||||
No new operators will be defined to mean "solve a set of linear
|
||||
equations", or "invert a matrix". Instead, NumPy will define a
|
||||
value "inv", which will be recognized by the exponentiation
|
||||
operator, such that "A ** inv" is the inverse of "A". This is
|
||||
similar in spirit to NumPy's existing "newaxis" value.
|
||||
equations", or "invert a matrix".
|
||||
|
||||
(Optional) When applied to sequences, the "@" operator will return
|
||||
a tuple of tuples containing the cross-product of their elements
|
||||
|
@ -293,7 +267,8 @@ Related Proposals
|
|||
|
||||
0225 : Elementwise/Objectwise Operators
|
||||
|
||||
A (much) larger proposal that addresses the same subject.
|
||||
A larger proposal that addresses the same subject, but
|
||||
which proposes many more additions to the language.
|
||||
|
||||
|
||||
Acknowledgments
|
||||
|
@ -313,19 +288,37 @@ References
|
|||
[7] http://www.python.org/pipermail/python-list/2000-August/112529.html
|
||||
|
||||
|
||||
Appendix: Other Operations
|
||||
Appendix: NumPy
|
||||
|
||||
NumPy will overload "@" to perform mathematical multiplication of
|
||||
arrays where shapes permit, and to throw an exception otherwise.
|
||||
Its implementation of "@" will treat built-in sequence types as if
|
||||
they were column vectors. This takes care of the cases MM and MV.
|
||||
|
||||
We considered syntactic support for three other operations:
|
||||
An attribute "T" will be added to the NumPy array type, such that
|
||||
"m.T" is:
|
||||
|
||||
T
|
||||
(a) transposition: A => A[j, i] for A[i, j]
|
||||
(a) the transpose of "m" for a 2-dimensional array
|
||||
|
||||
-1
|
||||
(b) inverse: A => A' such that A' * A = I (the identity matrix)
|
||||
(b) the 1xN matrix transpose of "m" if "m" is a 1-dimensional
|
||||
array; or
|
||||
|
||||
(c) solution: A/b => x such that A * x = b
|
||||
A\b => x such that x * A = b
|
||||
(c) a runtime error for an array with rank >= 3.
|
||||
|
||||
This attribute will alias the memory of the base object. NumPy's
|
||||
"transpose()" function will be extended to turn built-in sequence
|
||||
types into row vectors. This takes care of the VM, VD, and VO
|
||||
cases. We propose an attribute because:
|
||||
|
||||
(a) the resulting notation is similar to the 'superscript T' (at
|
||||
least, as similar as ASCII allows), and
|
||||
|
||||
(b) it signals that the transposition aliases the original object.
|
||||
|
||||
NumPy will define a value "inv", which will be recognized by the
|
||||
exponentiation operator, such that "A ** inv" is the inverse of
|
||||
"A". This is similar in spirit to NumPy's existing "newaxis"
|
||||
value.
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue