len() should always return something

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jul 26 11:45:03 CEST 2009


On Sat, 25 Jul 2009 16:21:39 -0700, Erik Max Francis wrote:

> Steven D'Aprano wrote:
>> But it's not "practically every function". It's hardly any function at
>> all -- in my code, I don't think I've ever wanted this behavior. I
>> would consider it an error for function(42) and function([42]) to
>> behave the same way. One is a scalar, and the other is a vector --
>> they're different things, it's poor programming practice to treat them
>> identically.
>> 
>> (If Matlab does this, so much the worse for Matlab, in my opinion.)
> 
> There's actually good reason to do this in heavily matrix-oriented
> specialized languages; there are numerous applications where scalars and
> 1x1 matrices are mathematically equivalent.


I'm curious what those applications are, because regular multiplication 
behaves differently depending on whether you have a 1x1 matrix or a 
scalar:

[[2]]*[[1, 2, 3], [2, 3, 4]] is not defined

2*[[1, 2, 3], [2, 3, 4]] = [[2, 4, 6], [2, 6, 8]]


I'm curious as to what these applications are, and what they're actually 
doing. Kronecker multiplication perhaps? Do you have some examples of 
those applications?



-- 
Steven



More information about the Python-list mailing list