[SciPy-User] idiom for iterators, expr(T) if isscalar(T) else array([expr(t) for t in T])
josef.pktd@gmai...
josef.pktd@gmai...
Fri Oct 16 12:10:06 CDT 2009
On Fri, Oct 16, 2009 at 12:12 PM, denis <denis-bz-gg@t-online.de> wrote:
> Thanks Josef,
>
> I've summarized this Q+A in http://advice.mechanicalkern.com
> of course, please edit it if you like.
> (That looks like a good place for such Q+A s, or
> http://stackoverflow.com/questions/tagged/scipy ?
> a separate discussion).
>
> cheers
> -- denis
One problem with doing the broadcasting for the user, is that it is
not always clear what the intention of the user is, although it might
be very suggestive from the context.
In your example:
# Worse,
print lerp( np.linspace( .1, .5, 3 ), p0, p1 )
# => a nonsense result, with no warning
This could also be exactly what the user wants, evaluate the function
at 3 points, taking one value from each array.
Or, if p0 and p1 are column vectors and t is 1d or row vector, the
user would get correctly broadcasted values but in row order.
I like your penalized least squares problem (more general than Ridge Regression)
A few comments to the broadcasting example:
I still think that "restrict" is not really the right word in "A way
to restrict broadcasting in such cases", better would be "to force
correct broadcasting".
To avoid the problem, with 2-dim arguments, I would ravel t and the p's first
Your scalar check doesn't check the dimension of p1.
Thanks for contributing to the docs.
Josef
More information about the SciPy-User
mailing list