[Python-ideas] Re: basic matrix object

2020-08-14 Thread Steven D'Aprano
On Thu, Aug 13, 2020 at 09:33:46PM -0700, Guido van Rossum wrote: > That's food for thought. I have to admit that I have forgotten almost > everything about linear algebra that I was ever taught In Australia, at least, secondary schools don't spend a lot of time teaching matrices for linear alge

[Python-ideas] Syntactic sugar for checking if a variable is an iterable but not a string?

2020-08-14 Thread Marco Sulla
Many times I want a function parameter that is an iterable but not a string. Usually I do: try: var.__iter__ except AttributeError: # not an iterable else: try: var.isascii except AttributeError: # put yuour code here or from collections.abc import Iterable if

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Marco Sulla
LaTeX for example uses the underscore for subscripts and the ^ for the superscript. This is not acceptable, since Python (and almost all languages) uses [] for subscript, and ^ in Python is the XOR logical operator. ___ Python-ideas mailing list -- pytho

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Marco Sulla
Excuse me, I sent this message from the wrong email address: On Fri, 14 Aug 2020 at 09:24, Steven D'Aprano wrote: > Tensors generalise matrices to an arbitrary number of > dimensions, 3D and above. > > https://medium.com/@quantumsteinke/whats-the-difference-between-a-matrix-and-a-tensor-4505fbdc5

[Python-ideas] Re: Syntactic sugar for checking if a variable is an iterable but not a string?

2020-08-14 Thread Chris Angelico
On Fri, Aug 14, 2020 at 6:46 PM Marco Sulla wrote: > > Many times I want a function parameter that is an iterable but not a > string. > from collections.abc import Iterable > > if isinstance(var, Iterable) and not isinstance(var, str): > # put yuour code here > Well, that line of code asks if

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Ricky Teachey
On Fri, Aug 14, 2020, 12:05 AM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > I cannot speak to engineering uses of matrix computations. If someone > produces use cases that fit into the list of operations proposed > (addition, negation, multiplication, inverse, transposition

[Python-ideas] PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Jonathan Fine
I'd like to sound out consensus regarding mapping access, where none of the keys are positional. In particular, I suggest that PEP 472 allow syntax and semantics such as >>> d[x=1, y=2] = 42 >>> d[x=1, y=2] 42 and ask whether the class >>> X = type(d) should be part of standard Pyth

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Greg Ewing
On 14/08/20 10:03 pm, Jonathan Fine wrote: NO POSITIONAL ARGUMENTS I'd like     >>> d[x=1, y=2] to be valid syntax. It's not clear to me that all agree with this. If keywords are to be allowed, it seems reasonable to me that this should be legal.     >>> d[x=1, y=2] = 42     >>> d[x=1, y=2

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Jonathan Fine
Hi Greg Thank you, for your support for d[x=1, y=2] being valid syntax. You ask if I have any use cases in mind for a general keyword key class being part of standard Python. Good question. Anyone who is experimenting with keyword keys would, I think, appreciate having something they can use str

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Ricky Teachey
It seems very obvious to me that kwd args only should be valid, as Greg Ewing said, if kwd args are added. I'm less sure about no arguments, but perhaps. On Fri, Aug 14, 2020, 8:11 AM Jonathan Fine wrote: > Storing function call results would be a use case. For this, look at the > implementatio

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Paul Moore
On Fri, 14 Aug 2020 at 13:12, Jonathan Fine wrote: > Anyone who is experimenting with keyword keys would, I think, appreciate > having something they can use straight away. Thus, I think, any use case for > PEP 472 is also a use case for the general keyword class I'm suggesting. No > use cases

[Python-ideas] Re: basic matrix object

2020-08-14 Thread fribl
In my role as an engineering professor and instructor, I find linear algebra to be essential. To my knowledge, almost any book on engineering mathematics contains a large section on linear algebra. numpy is an extremely useful package, but is overwhelming for some novices (e.g. dealing with the

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Greg Ewing
Another class of folks who might find something like this useful is those playing around with computer graphics using pygame, pyglet, etc. where coordinate transformations are used a lot. Bringing in numpy for that can seem like massive overkill for a tiny game. -- Greg __

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Greg Ewing
On 14/08/20 9:05 pm, Marco Sulla wrote: Another big problem with tensors is the covariance and contravariance. Usually in informatic you denote the covariance with the subscript operator, that on paper is written as subscript. Contravariant index on the contrary is a superscript. Not sure how a p

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Stephen J. Turnbull
Guido van Rossum writes: > That's food for thought. Thank you. Let me confirm to the proponents that "food for thought" is all I intended. I know a fair amount about statistics, and almost as much about linear algebra, but nothing about physics or engineering. > Certainly I trust [Steven D'A

[Python-ideas] Not-so-basic tensors [was: basic matrix object]

2020-08-14 Thread Stephen J. Turnbull
Marco Sulla writes: > Another big problem with tensors is the covariance and contravariance. > Usually in informatic you denote the covariance with the subscript > operator, that on paper is written as subscript. Contravariant index > on the contrary is a superscript. You're talking about the

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Stephen J. Turnbull
Ricky Teachey writes: > I'll try to speak to [what would engineers use a matrix library > for] below. I don't get it. Among other things, the object uwt_per_ft isn't defined. I think it's a typo for the one-dimensional array γ_per_foot, but not sure. I don't see any advantage to numpy or a m

[Python-ideas] Re: basic matrix object

2020-08-14 Thread Ricky Teachey
On Fri, Aug 14, 2020 at 1:32 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Ricky Teachey writes: > > > I'll try to speak to [what would engineers use a matrix library > > for] below. > > I don't get it. Among other things, the object uwt_per_ft isn't > defined. I think

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Caleb Donovick
My own personal use for this would be for generating anonymous protocols and dataclasses: class T(Protocol): x: int y: str # with some abuse of notation obviously these would generate unique typesassert T == Struct[x=int, y=str] # similarly @dataclassclass S: x: int y: str assert S =

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread David Mertz
On Fri, Aug 14, 2020, 7:39 PM Caleb Donovick > class T(Protocol): > x: int > y: str > # with some abuse of notation obviously these would generate unique > typesassert T == Struct[x=int, y=str] > > I don't see what that can possible get you that `Struct(x=int, y=str)` doesn't. I'm +0 on

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Caleb Donovick
> I don't see what that can possible get you that `Struct(x=int, y=str)` doesn't. Using `Struct(x=int, y=str)` requires a metaclass, where `Struct[x=int, y=str]` does not. On Fri, Aug 14, 2020 at 4:45 PM David Mertz wrote: > On Fri, Aug 14, 2020, 7:39 PM Caleb Donovick > >> class T(Protocol):

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread David Mertz
On Fri, Aug 14, 2020, 7:53 PM Caleb Donovick wrote: > > I don't see what that can possible get you that `Struct(x=int, y=str)` > doesn't. > > Using `Struct(x=int, y=str)` requires a metaclass, where `Struct[x=int, > y=str]` does not. > Why would it require a metaclass? Rather than just: class S

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Ricky Teachey
On Fri, Aug 14, 2020, 7:45 PM David Mertz wrote: > On Fri, Aug 14, 2020, 7:39 PM Caleb Donovick > >> class T(Protocol): >> x: int >> y: str >> # with some abuse of notation obviously these would generate unique >> typesassert T == Struct[x=int, y=str] >> >> I don't see what that can poss

[Python-ideas] Re: Not-so-basic tensors [was: basic matrix object]

2020-08-14 Thread Greg Ewing
On 15/08/20 5:31 am, Stephen J. Turnbull wrote: It seems to me you could have a Tensor class whose constructor takes a bool argument 'contravariant' (default False), and then recommend that users adopt a naming convention to distinguish covariant Tensors from contravariant Tensors. You would ne

[Python-ideas] Re: Syntactic sugar for checking if a variable is an iterable but not a string?

2020-08-14 Thread Steven D'Aprano
On Fri, Aug 14, 2020 at 10:43:31AM +0200, Marco Sulla wrote: > Many times I want a function parameter that is an iterable but not a > string. Usually I do: > > try: > var.__iter__ > except AttributeError: > # not an iterable > else: > try: > var.isascii > except AttributeEr

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Steven D'Aprano
On Fri, Aug 14, 2020 at 08:45:44AM -0400, Ricky Teachey wrote: > It seems very obvious to me that kwd args only should be valid, as Greg > Ewing said, if kwd args are added. Absolutely. We shouldn't even need to debate this. Would we consider a language change that forced every single function t

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Steven D'Aprano
On Fri, Aug 14, 2020 at 04:07:33PM -0700, Caleb Donovick wrote: > My own personal use for this would be for generating anonymous protocols > and dataclasses: > > class T(Protocol): > x: int > y: str > # with some abuse of notation obviously these would generate unique > typesassert T == St

[Python-ideas] Re: PEP 472 - regarding d[x=1, y=2] and similar

2020-08-14 Thread Steven D'Aprano
On Fri, Aug 14, 2020 at 08:58:36PM -0400, Ricky Teachey wrote: > One problem is type hint creation has been extended to built-ins in python > 3.9, so that you do not have to import Dict, List, et al anymore. > > Without kwd args inside [ ], you would not be able to do this: > > Vector = dict[i=f