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.
|
definitive historical record.
|
||||||
|
|
||||||
|
|
||||||
Proposal
|
Summary
|
||||||
|
|
||||||
Add a single new infix binary operator '@' ("across"), and
|
Add a single new infix binary operator '@' ("across"), and
|
||||||
corresponding special methods "__across__()", "__racross__()", and
|
corresponding special methods "__across__()", "__racross__()", and
|
||||||
|
@ -141,38 +141,12 @@ Proposal
|
||||||
|
|
||||||
A new operator '@' (pronounced "across") will be added to Python,
|
A new operator '@' (pronounced "across") will be added to Python,
|
||||||
along with special methods "__across__()", "__racross__()", and
|
along with special methods "__across__()", "__racross__()", and
|
||||||
"__iacross__()", with the usual semantics.
|
"__iacross__()", with the usual semantics. (We recommend using
|
||||||
|
"@", rather than the times-like "><", because of the ease with
|
||||||
NumPy will overload "@" to perform mathematical multiplication of
|
which the latter could be mis-typed as inequality "<>".)
|
||||||
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.
|
|
||||||
|
|
||||||
No new operators will be defined to mean "solve a set of linear
|
No new operators will be defined to mean "solve a set of linear
|
||||||
equations", or "invert a matrix". Instead, NumPy will define a
|
equations", or "invert a matrix".
|
||||||
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.
|
|
||||||
|
|
||||||
(Optional) When applied to sequences, the "@" operator will return
|
(Optional) When applied to sequences, the "@" operator will return
|
||||||
a tuple of tuples containing the cross-product of their elements
|
a tuple of tuples containing the cross-product of their elements
|
||||||
|
@ -293,7 +267,8 @@ Related Proposals
|
||||||
|
|
||||||
0225 : Elementwise/Objectwise Operators
|
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
|
Acknowledgments
|
||||||
|
@ -313,19 +288,37 @@ References
|
||||||
[7] http://www.python.org/pipermail/python-list/2000-August/112529.html
|
[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) the transpose of "m" for a 2-dimensional array
|
||||||
(a) transposition: A => A[j, i] for A[i, j]
|
|
||||||
|
|
||||||
-1
|
(b) the 1xN matrix transpose of "m" if "m" is a 1-dimensional
|
||||||
(b) inverse: A => A' such that A' * A = I (the identity matrix)
|
array; or
|
||||||
|
|
||||||
(c) solution: A/b => x such that A * x = b
|
(c) a runtime error for an array with rank >= 3.
|
||||||
A\b => x such that x * A = b
|
|
||||||
|
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