Multi-dimensional list initialization
joshua.landau.ws at gmail.com
Thu Nov 8 01:46:03 CET 2012
On 7 November 2012 23:55, Andrew Robinson <andrew3 at r3dsolutions.com> wrote:
> On 11/07/2012 05:39 AM, Joshua Landau wrote:
> A more modest addition for the limited case described in this thread
>> could be to use exponentiation:
>> >>>  ** (2, 3)
>> [[0, 0, 0], [0, 0, 0]]
> I'm against over using the math operators, for the reason that matrix
> and vector algebra have meanings mathematicians desire (rightly) to
> maintain. Numpy users might find matricies overloaded to do these things
> in the future -- and then it becomes unclear whether an initialization is
> happening or a mathematical operation. I think it best just not to set up
> an accident waiting to happen in the first place.
I'm going to say right now that I'm very much fond of
the exponentiation proposal.
Multiplication on Numpy arrays is already completely disjoint to
multiplication on lists, and that is probably completely disjoint to all
sorts of mathematical meanings. I don't personally feel that anyone who
knows what  * 3 is would *assume* (although they may suppose)
that exponentiation will be a maths operator.
When I saw  ** (2, 3), I knew what it did before I read anything else. I
know I had the context of the posts above, so it isn't a fair comparison,
but it seems really obvious an extension. It's so closely linked to * (if
not for the ambiguities, I would have preferred multiplication) that it
makes total sense. Even if you think of "4 ** 5" as "4 * 4, 5 times", there
is a direct mental link to what is happening.
> Hold on: why not just use multiplication?
> >>>  * (2, 3)
> Would you consider that better than .nest(2).nest(3) ? or .nest(2,3)
> (I'm against multiplication, but I'm still interested in what you find
> attractive about it.)
Having  * 2 with a distinct but fundamentally the same (it's just gotten
extra dimensions) partner that is called in a very similar way is a good
I'd feel equally unhappy with "4 * 3" partnering with "(4).pow(3)"* as I
would with your .nest(2, 3) and I like the iterated ones even less because
I don't see it as obviously possible for them to even work.
.nest(2) -> [, ] ?
[, ].nest(3) -> [[0,0,0], [0,0,0]] ???
(what about 3d?)
* Even if you could write that as "4.pow(3)" because floats didn't exist or
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list